VB.NET Nullable 语法的历史 [英] History of VB.NET Nullable syntax

查看:58
本文介绍了VB.NET Nullable 语法的历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到确切的答案.从 C# 2.0 开始,您就可以声明

I can't find a definitive answer. Since C# 2.0 you've been able to declare

int? i = 125;

作为简写

Nullable<int> i = Nullable<int>(123);

我记得在某处读到 VB.NET 不允许使用此快捷方式.但是,瞧,我今天在 VS 2008 中尝试了它,并且它有效.

I recall reading somewhere that VB.NET did not allow this shortcut. But low and behold, I tried it in VS 2008 today and it works.

有谁知道它是从 .NET 2.0 开始还是后来添加的?

Does anyone know whether it's been this way since .NET 2.0 or was this added later?

推荐答案

System.Nullable 是在 .Net 2.0 中引入的,可用于 VB 作为泛型类型.您只是不能使用可为空的语法.所以在 VS 2005 中你可以这样做:

System.Nullable was introduced in .Net 2.0 and is available to VB as a generic type. You just cannot use the nullable syntax. So in VS 2005 you can do:

Dim x as Nullable(of Integer)

我不知道空等价和装箱是否适用于 VB 2005 中的可空值,但我怀疑答案是肯定的,因为 .Net 团队对 2.0 CLR 进行了更改以完成可空值的装箱.我想 VB 会利用这一点.

I don't know if null equivalence and boxing works for nullables in VB 2005, but I would suspect that the answer is yes since the .Net team made a change to the 2.0 CLR to accomplish boxing with nullables. I would imagine VB leverages this.

在 2008 年,您显然可以这样做:

In 2008, you can obviously just do:

Dim x as Integer?

这篇关于VB.NET Nullable 语法的历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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