C# 中的集合
将 vb.net 组件转换为 C# 时,出现此错误
Using the generic type 'System.Collections.ObjectModel.Collection
s
这是我在 VB.NET 中所做的
我有这个
Private _bufferCol As Collection
我在 c# 中做了这个
private Collection _bufferCol = new Collection();
我的声明是
using Microsoft.VisualBasi;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections.ObjectModel;
任何人都可以帮助我吗?
am converting a vb.net component to c#, i get this error
Using the generic type 'System.Collections.ObjectModel.Collection<T>' requires '1' type argument
s
This is what i did
in VB.NET i had this
Private _bufferCol As Collection
i did this in c#
private Collection _bufferCol = new Collection();
My declaration is
using Microsoft.VisualBasi;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections.ObjectModel;
Can any body help me please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它很混乱,因为 Microsoft.VisualBasic 和 System.Collections.ObjectModel 命名空间中都有一个名为“Collection”的类型。您可以像这样修复直接翻译的问题:
但我不建议这样做。 Microsoft.VisualBasic 命名空间主要用于更轻松地从旧的 vb6 时代代码迁移。你真的不应该再使用它的 Collection 类型。
相反,请调整此代码以使用通用
List
或Collection
。It's confused because there is a type named "Collection" in both the Microsoft.VisualBasic and the System.Collections.ObjectModel namespaces. You can fix things for a direct translation like this:
But I don't recommend doing that. The Microsoft.VisualBasic namespace is intended mainly for easier migration away from older vb6-era code. You really shouldn't use it's Collection type any more.
Instead, adapt this code to use a generic
List<T>
orCollection<T>
.您需要集合的类型声明。也就是说,您的藏品是什么类型的?
例如:
You need a Type declaration fro your collection. That is, what type is your collection holding?
For instance:
正如它所说,您需要指定存储在集合中的对象的类型。
当你有:
这个
T
表示集合中对象的类型。如果您需要接受所有类型的对象,只需使用
As it says, you need to specify the type of objects stored in collection.
When you have:
this
T
means the type of your objects in collection.If you need to accept all types of objects, just use
您正在尝试使用类型化集合< /a> 在 C# 中,但未指定类型。
尝试
其中 MyType 是您要放入集合中的事物的类型。
C# 允许您对集合、列表、集合等进行强类型化,以便了解它们所包含的内容并可以在编译时进行检查。
You are attempting to use a typed collection in C# but not specifying the type.
Try
Where MyType is the type of the thing you want to put in the collection.
C# allows you to strongly type collections, lists, sets, etc so that the kind of thing they contain is known and can be checked at compile time.