Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collections in C#

Tags:

c#

collections

am converting a vb.net component to c#, i get this error

Using the generic type 'System.Collections.ObjectModel.Collection<T>' requires '1' type arguments

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.

like image 746
Smith Avatar asked May 24 '26 11:05

Smith


1 Answers

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:

private Microsoft.VisualBasic.Collection _buffer = new Microsoft.VisualBasic.Collection();

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> or Collection<T>.

like image 82
Joel Coehoorn Avatar answered May 25 '26 23:05

Joel Coehoorn