其中在学习Attribute Class的过程中发现Type Class的用法,很多Method并没有试探,只是略微介绍一下Type中的GetMethod()方法。
在学习过程中总结C#的数据类型
1 Value Types 其中包括Int, Long Int...
2 Reference Types其中包括Object,String,Dynamic.其中Object实在编译中检查,而Dynamic是在运行中检查
3 Point Type 其中和C和C++中的Point Type是一样的。
using System;
using System.Reflection;
namespace _2011._12._15
{
class Program
{
static void Main(string[] args)
{
Test testone = new Test();
string s = testone.GetType().ToString();
Console.WriteLine("GetType():");
Console.WriteLine(s);//_2011._12._15.Test 命名空间的Test类
Type type = typeof(Test);
Console.WriteLine("Typeof():");
Console.WriteLine(type);//_2011._12._15.Test 命名空间的Test类
Console.WriteLine();
MethodInfo[] methodinfo = type.GetMethods();
Console.WriteLine(methodinfo.GetType());//System.Reflection.MethodInfo[]
foreach (var i in methodinfo)
{
Console.WriteLine(i);//输出Test类的所有方法及继承Object的实例方法
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
MemberInfo[] memberinfo = type.GetMembers();
Console.WriteLine(memberinfo.GetType());
foreach (var i in memberinfo)
{
Console.WriteLine(i);//输出Test类字段和System.type类型
}
Console.WriteLine();
testone.speaking();
testone.writing();
Console.ReadKey();
}
}
class Test
{
private int age;
public string name;
public void speaking()
{
age = 10;
Console.WriteLine("Welcome to cnblog!" + age);
}
public void writing()
{
name = "Hello";
Console.WriteLine("Please writing something!"+ name);
}
}
}