虽说我不怎么相信国外的月亮比国内圆,但在IT业这块,不得不承认国外确实比国内牛。读了《C#和.NET2.0实战(平台语言与框架)》与《CLR VIA C#》(第三版)后,让我对以前很多不明白的地方有了更加深入的与完整的认识。
首先是.net程序集的组成:
然后是.net程序的内存布局:
代码
using System;
namespace CPUTest
{
class Program
{
static void Main(string[] args)
{
CPU intel = new INTEL();
intel.Work();
CPU amd = new AMD();
amd.Work();
string str = "abc";
byte[] bytes = new byte[1000000];
Console.ReadKey();
}
}
class CPU
{
public CPU()
{
Console.WriteLine("init cpu");
}
public virtual void Work()
{
Console.WriteLine("cpu");
}
}
class AMD : CPU
{
public AMD()
{
Console.WriteLine("init amd");
}
public override void Work()
{
Console.WriteLine("amd");
}
}
class INTEL : CPU
{
public INTEL()
{
Console.WriteLine("init intel");
}
public new void Work()
{
Console.WriteLine("intel");
}
}
}
namespace CPUTest
{
class Program
{
static void Main(string[] args)
{
CPU intel = new INTEL();
intel.Work();
CPU amd = new AMD();
amd.Work();
string str = "abc";
byte[] bytes = new byte[1000000];
Console.ReadKey();
}
}
class CPU
{
public CPU()
{
Console.WriteLine("init cpu");
}
public virtual void Work()
{
Console.WriteLine("cpu");
}
}
class AMD : CPU
{
public AMD()
{
Console.WriteLine("init amd");
}
public override void Work()
{
Console.WriteLine("amd");
}
}
class INTEL : CPU
{
public INTEL()
{
Console.WriteLine("init intel");
}
public new void Work()
{
Console.WriteLine("intel");
}
}
}
其实如果看过那两本书,或是对这方面有一些研究的话,就不需要我作额外的解释(比如多态的实现),一切尽在不言中了。
参考的文章: