C# 中 is object 和 is {} 有什么区别 [英] What's the difference between is object and is {} in C#

查看:41
本文介绍了C# 中 is object 和 is {} 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我认为在当前的 C# 版本中是 C# 8.有几种方法可以检查引用类型是否不是 null.我对下面这两个感到困惑:

So, I think in the current C# version which is C# 8. There are a few ways to check the reference types are not null. I am confused by these two below:

  1. o 是对象
  2. o 是 {}

它们之间的主要区别是什么,我找不到关于它们的太多信息.

What's the main difference between them, I cannot find much info for them.

谁能给我解释一下?推荐哪一款?或者每种方法的优缺点是什么?

Can someone explain it to me? Which one is recommended? Or what are the pro and cons of each one?

推荐答案

  1. o is object 是检查实例类型的原始方法(自 C# 1.0 起可用)

  1. o is object is the original way of checking the type of an instance (available since C# 1.0)

o is {} 使用与 C# 8.0 中引入的属性模式

{} 表示具有任何(或无)属性的对象实例,即任何对象实例.

{} denotes an object instance with any (or none) properties, i.e. any object instance.

这篇关于C# 中 is object 和 is {} 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆