在VB.NET中,New语句后如何内联调用实例方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计247个文字,预计阅读时间需要1分钟。
要将现代代码转换为VB.NET的`public void SetBooks(IEnumerable books)`方法,并保持简洁且不超过100个字,可以简化如下:
vbPublic Sub SetBooks(books As IEnumerable(Of Book)) If books Is Nothing Then Throw New ArgumentNullException(books) Dim filename As String=books.xml Dim xdoc As New XDocument(books) xdoc.Save(filename)End Sub
我怎样才能将此代码转换为VB.netpublic void SetBooks(IEnumerable<Book> books) { if (books == null) throw new ArgumentNullException("books"); new System.Xml.Linq.XDocument(books).Save(_filename); }
在converter.telerik.com/它说:
Public Sub SetBooks(books As IEnumerable(Of Book)) If books Is Nothing Then Throw New ArgumentNullException("books") End If New System.Xml.Linq.XDocument(books).Save(_filename) End Sub
但是visual studio说“语法错误”.因为“新”
这种情况的关键字是什么,我在Google上搜索但没有结果.
您无法初始化对象并在VB.NET中的一个语句中使用它(而不是C#).你需要两个:Dim doc = New System.Xml.Linq.XDocument(books) doc.Save(_filename)
在C#中构造函数returns the instance of the created object,在VB.NET中没有.
本文共计247个文字,预计阅读时间需要1分钟。
要将现代代码转换为VB.NET的`public void SetBooks(IEnumerable books)`方法,并保持简洁且不超过100个字,可以简化如下:
vbPublic Sub SetBooks(books As IEnumerable(Of Book)) If books Is Nothing Then Throw New ArgumentNullException(books) Dim filename As String=books.xml Dim xdoc As New XDocument(books) xdoc.Save(filename)End Sub
我怎样才能将此代码转换为VB.netpublic void SetBooks(IEnumerable<Book> books) { if (books == null) throw new ArgumentNullException("books"); new System.Xml.Linq.XDocument(books).Save(_filename); }
在converter.telerik.com/它说:
Public Sub SetBooks(books As IEnumerable(Of Book)) If books Is Nothing Then Throw New ArgumentNullException("books") End If New System.Xml.Linq.XDocument(books).Save(_filename) End Sub
但是visual studio说“语法错误”.因为“新”
这种情况的关键字是什么,我在Google上搜索但没有结果.
您无法初始化对象并在VB.NET中的一个语句中使用它(而不是C#).你需要两个:Dim doc = New System.Xml.Linq.XDocument(books) doc.Save(_filename)
在C#中构造函数returns the instance of the created object,在VB.NET中没有.

