判断类型
- 获取变量的类型对象
string str = "Hello World";
Console.WriteLine(str.GetType());
- 获取类型
int num = 10;
Console.WriteLine(num.GetType() == typeof(int));
- is 方法
enum Sex
{
male,
Female
}
Sex sex = Sex.male;
Console.WriteLine(sex is Enum);
string str = "Hello World";
Console.WriteLine(str.GetType());
int num = 10;
Console.WriteLine(num.GetType() == typeof(int));
enum Sex
{
male,
Female
}
Sex sex = Sex.male;
Console.WriteLine(sex is Enum);
本文标题:判断类型
本文链接:https://www.haomeiwen.com/subject/ozenbrtx.html
网友评论