gpt4 book ai didi

.net - 与 Visual Basic 关键字(例如 `System.String` )相比,使用 CLR 类型(例如 `[String]` 或 `String` )是否有任何可以想象的优势?

转载 作者:行者123 更新时间:2023-12-01 06:09:00 25 4
gpt4 key购买 nike

我们都知道在 C# 中使用 String 没有任何区别。 (CLR 类)或 string (C# 关键字)。有关详细信息,请参阅以下问题:

  • What is the difference between String and string in C#?

  • 到目前为止,我的印象是 VB.NET 也是如此。 language specification甚至说(强调我的):

    The primitive types are identified through keywords, which are aliases for predefined types in the System namespace. A primitive type is completely indistinguishable from the type it aliases: writing the reserved word Byte is exactly the same as writing System.Byte.



    因此,我很惊讶地看到 Visual Studio 2015 有所作为:Visual Studio 允许您指定框架名称(Int32/Int64/DateTime/...)的偏好(工具/选项/文本编辑器/基本/代码样式)在 native VB 关键字(整数/长/日期/...)。

    问题是:一旦你告诉 Visual Studio 你更喜欢框架名称,自动生成的代码使用 [String] (使用 [] VB 关键字转义,类似于 C# 的 @ )而不是 String (对于 Object、Single 和所有其他类型,其中 VB 关键字与 Framework 类型名称匹配)。我认为这是错误的(并且已经提交了 Connect issue ),因为括号使代码困惑,并且如上所述,无论您使用 [String] 都没有语义差异(有效引用 System.String 由于 VB 的自动 System 导入)或 String (VB 关键字别名 System.String )。

    然而,由于 Visual Studio 开发人员是非常聪明的人,我完全有可能只是忽略了一些东西,而使用 [String] 实际上是有意义的。而不是 String ,因此我的问题:

    使用 [String] 是否有任何可以想象的优势?而不是 String在 Visual Basic 中 还是 Visual Studio 编辑器只是“做错了事”并且无用地困惑了自动生成的代码?

    最佳答案

    我认为使用 String(引用(1))会比 [String] 更连续.使用 [String]到处都只是在 VB 的语法颜色中看起来不太好,因为它看起来像一个普通类型而不是关键字。我认为使用 [String] 没有想象中的优势。而不是 String在用 VB 语法着色时的外观以外的代码中。

    关于.net - 与 Visual Basic 关键字(例如 `System.String` )相比,使用 CLR 类型(例如 `[String]` 或 `String` )是否有任何可以想象的优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34513752/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com