作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 C# 中,您可以像这样创建一个实例:
Custom mycustomelement = new Custom { ElenentName = "My Custom Element" };
我想知道如何在 Visual Basic 中创建这样的实例以及这种类型的创建实例的名称。
最佳答案
它叫做 object initializer , 和 corresponding VB.NET syntax是:
Dim mycustomelement As New Custom With { .ElementName = "My Custom Element" }
(注意属性名前的点(.
),符合VB的With
语句的语法。)
请注意,在使用 object initializer syntax for anonymous types 时,C# 和 VB 之间存在细微差别。 : 在 C# 中,所有属性都是不可变的;在 VB 中,它们是可变的,除非使用 Key
关键字进行初始化。
关于.net - 什么是 VB.NET 等同于这种创建实例的方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70896475/
判断这2个相似的Uris实际上相同的标准方法是什么? var a = new Uri("http://sample.com/sample/"); var b = new Uri("http://sam
这个问题在这里已经有了答案: Why does "true" == true show false in JavaScript? (5 个答案) 关闭 5 年前。 可能我很困惑,但我无法理解这个愚蠢
我是一名优秀的程序员,十分优秀!