所有栏目 | 云社区 美国云服务器[国内云主机商]
你的位置:首页 > 云社区 » 正文

C#中,判断变量类型的语句?

发布时间:2020-04-15 16:50:35

资讯分类:变量  语句  判断  类型  就可以  在这个  中有
C#中,判断变量类型的语句?

在C#中有一个关键字叫做is,就可以解决这个问题。例如:

using System;

using System.Collections.Generic;

using System.Text;

namespace mghm

{

class Program

{

static void Main(string[] args)

{

string s = "BBEijing";

int a = 123;

bool b = true;

bool result = (s is string);//在这个地方改变就可以测试了。

Console.WriteLine("result=" + result);//结果为true,则说明s为string类型。

}

}

}

留言与评论(共有 0 条评论)
   
验证码:
Top