在C#中获取当前实例的类型
要获取当前实例的类型,代码如下-
示例
using System;public class Demo {
public static void Main(){
string s = "Demo";
Console.WriteLine("String = " +s);
Console.WriteLine("String Type = " +s.GetType());
}
}
输出结果
这将产生以下输出-
String = DemoString Type = System.String
示例
现在让我们来看另一个示例-
using System;public class Demo {
public static void Main(){
double val1 = 5.5;
int val2 = 10;
short val3 = 2;
Console.WriteLine("Value = " +val1);
Console.WriteLine("Value Type = " +val1.GetType());
Console.WriteLine("Value = " +val2);
Console.WriteLine("Value Type = " +val2.GetType());
Console.WriteLine("Value = " +val3);
Console.WriteLine("Value Type = " +val3.GetType());
}
}
输出结果
这将产生以下输出-
Value = 5.5Value Type = System.Double
Value = 10 Value
Type = System.Int32
Value = 2 Value
Type = System.Int16
以上是 在C#中获取当前实例的类型 的全部内容, 来源链接: utcz.com/z/338503.html