
"is" 关键字用于检查对象是否可以转换为特定类型。操作的返回类型为Boolean。
本文档主要讲述的是Python开发网站指南;HTML是网络的通用语言,一种简单、通用的全置标记语言。它允许网页制作人建立文本与图片相结合的复杂页面,这些页面可以被网上任何其他人浏览到,无论使用的是什么类型的电脑或浏览器 Python和其他程序语言一样,有自身的一套流程控制语句,而且这些语句的语法和其它程序语言类似,都有for, if ,while 类的关键字来表达程序流程。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
0
using System;
namespace DemoApplication{
class Program{
static void Main(){
Employee emp = new PermanentEmployee{
ID = 1,
Name = "Martin"
};
// Returns true as the derived type can be converted to base type.
if (emp is Employee){
Console.WriteLine(emp.Name + " is Employee");
}
else{
Console.WriteLine(emp.Name + " is not Employee");
}
//Returns true, as the actual object is of type PermanentEmployee.
if (emp is PermanentEmployee){
Console.WriteLine(emp.Name + " is PermanentEmployee");
}
else{
Console.WriteLine(emp.Name + " is not PermanentEmployee");
}
//Returns false, as PermanentEmployee object cannot be converted to
//ContractEmployee.
if (emp is ContractEmployee){
Console.WriteLine(emp.Name + " is ContractEmployee");
}
else{
Console.WriteLine(emp.Name + " is not ContractEmployee");
}
}
}
class Employee{
public int ID { get; set; }
public string Name { get; set; }
}
class PermanentEmployee : Employee{
public int AnnualSalary { get; set; }
}
class ContractEmployee : Employee{
public int HourlySalary { get; set; }
}
}以上就是C# 中“is”关键字有什么用?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号