First we try, then we trust

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
最近研究C#中的Type是什么,不得已找到了微软公开的ROTOR代码,分析半天还是一头雾水。System.Type类中包含了System.Reflection.FieldInfo类型的数据,FieldInfo继承自System.Reflection.MemberInfo类,本以为MemberInfo的父类是Object就到头了,可一看代码才发现MemberInfo中居然包含有Type类型的数据!

于是产生一个问题:到底是先有鸡还是先有蛋?看下面的代码:

using System;

class Client
{
   
public static void Main ()
   
{
      Base b 
= new Base();
      Derived d 
= new Derived();
      b.d 
= d;
      Console.WriteLine(b.d.m);      
   }

}


class Base
{
   
public int n = 9;
   
public Derived d;
}


class Derived : Base
{
   
public int m = 10;   
}

Derived继承自Base,可以说没有Base就没有Derived,可Base里面有一个成员是Derived类型。这个程序可以正常编译执行并打印结果10。始终想不明白。

我感觉程序在编译时,先生成Type信息,然后再进一步处理,这由绕到了原来的问题,什么是Type呢?
posted on 2004-08-03 16:49  吕震宇  阅读(1560)  评论(8编辑  收藏  举报