C#自省

1、根据string,获取type。Type.GetType 方法,获取具有指定名称的 Type,执行区分大小写的搜索。

  C#自省

2、根据obj,获取type。Object.GetType 方法,获取当前实例的 Type

  C#自省

int n1 = 12;
int n2 = 82;
long n3 = 12;

Console.WriteLine("n1 and n2 are the same type: {0}",
                  Object.ReferenceEquals(n1.GetType(), n2.GetType()));
Console.WriteLine("n1 and n3 are the same type: {0}",
                  Object.ReferenceEquals(n1.GetType(), n3.GetType()));
// The example displays the following output:
//       n1 and n2 are the same type: True
//       n1 and n3 are the same type: False      
View Code

相关文章:

  • 2021-08-26
  • 2022-02-13
  • 2021-07-01
  • 2021-12-09
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2021-09-17
  • 2021-11-10
  • 2021-09-06
  • 2021-09-28
  • 2021-11-11
相关资源
相似解决方案