惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
J
Java Code Geeks
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
雷峰网
雷峰网
D
DataBreaches.Net
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
V
Visual Studio Blog
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta

博客园 - gjcn

2011,美好生活的一年 8万亿 全球第二还是最二? CLR系列:浅析委托 CLR系列:浅析.NET的JIT编译 CLR系列:浅析泛型的本质 Linq系列:基础与本质(Part III) Linq系列:基础与本质(Part II) Linq系列:基础与本质(Part I) CLR系列:由一段代码所想到的 {Agile},{CMMI},现状 CLR系列:大型对象堆 CLR系列:窥视HashTable c#3.0系列:Object Initializer 和 Collection Initializer c#3.0系列:Extension Method c#3.0系列:Automatic Property c#3.0系列:Anonymous Type In CLR(3.5) - gjcn Quiz:who win in finally vs return? Multi-Language of web application project ASP.NET应用程序的文件组成及编译过程
Inside C#(一些内部实现的东西)
gjcn · 2008-03-04 · via 博客园 - gjcn

ILDASM是个好的工具,平时也很喜欢用,它能帮助我更好的了解NET。以下我的总结,请执教。

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 是struct ,内部成员即是struct 也是Enum 。
2)Enum 继承System.Enum 的,structs可以继承ValueType,也可以是Enum 。
3)Enum 内部成员默认是Int的。
4)变量含有”__“的不能使用。
5)所有的值都是const 的,因此在没有重新编译的时候是不能改变的,而且也是类型安全的。
 

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)解析函数是重写基类的finalize 的。且是不确定的。
2)method (represented by the “…”)是放在Try里,无论有没有异常都会调用基类的finalize 。

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:

使用using 会被编译成try,且会始终执行Dispose方法(基于CLR的异常)。

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(); 
                }
}

版权所有归"布衣软件工作者".未经容许不得转载.