vb.net – 在New语句之后调用实例方法内联
发布时间:2020-12-17 07:24:14 所属栏目:百科 来源:网络整理
导读:我怎样才能将此代码转换为VB.net public void SetBooks(IEnumerableBook books) { if (books == null) throw new ArgumentNullException("books"); new System.Xml.Linq.XDocument(books).Save(_filename); } 在http://converter.telerik.com/它说: Public
我怎样才能将此代码转换为VB.net
public void SetBooks(IEnumerable<Book> books) { if (books == null) throw new ArgumentNullException("books"); new System.Xml.Linq.XDocument(books).Save(_filename); } 在http://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中没有. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |