Ildasm is a good tool that I like very much at ordinary times. It can help me better understand net. In my summary, please teach.
You write:
Public Enum compression {
Zip, superzip, none
}
The C # compiler generates:
Public struct compression: Enum {
Public int value __;
Public const compression zip = 0;
Public const compression superzip = 1;
Public const compression none = 2;
}
What can we learn:
1)Enums is struct, and the internal Member is struct and enum.
2) Enum inherits from system. enum. structs can inherit from valuetype or enum.
3) The Enum internal Member is int by default.
4) variables containing "_" cannot be used.
5) All values are const, so they cannot be changed without re-compilation, and are also type-safe.
You write:
Public class Resource
{
~ Resource (){
...
}
}
The C # compiler generates:
Public class Resource
{
Protected override void finalize (){
Try {
...
}
Finally {
Base. Finalize ();
}
}
}
What can we learn:
1) The parsing function overrides the Finalize of the base class. And it is uncertain.
2) method (represented by the "…") Put it in try. The finalize of the base class is called no matter whether there is any exception.
You write:
Using (resource res = new resource ()){
Res. dowork ();
}
The C # compiler generates:
Resource res = new resource (...);
Try {
Res. dowork ();
}
Finally {
If (res! = NULL)
(Idisposable) RES). Dispose ();
}
What can we learn:
UseUsingWill be compiled into try, and will always execute the dispose method (CLR-based exception ).
You write:
Object x = ...;
Lock (x ){
// Critical section
}
The C # compiler generates:
System. Threading. Monitor. Enter (X );
Try {
// Critical section
}
Finally {
System. Threading. Monitor. Exit (X );
}
What can we learn:
1)Lock just uses monitor. enter and exit... Reading those docs give you a good idea of what is really happening here.
2)We see our friend try... finally again. This time ensuring that the monitor is exited even if an exception is thrown in the critical section
You write:
Arraylist list = new arraylist ();
Foreach (int x in list) {// do nothing}
The C # compiler generates:
Arraylist list1;
Int num1;
Ienumerator enumerator1;
Idisposable disposable1;
List1 = new arraylist ();
Enumerator1 = list1.getenumerator ();
Try {
While (enumerator1.movenext ()){
Num1 = (INT) enumerator1.current );
}
Return;
}
Finally {
Disposable1 = (enumerator1 as idisposable );
If (disposable1! = NULL ){
Disposable1.dispose ();
}
}