Generic Collection<t>

I am trying to compile a code using Collection, but Visual Express C# 2008 says that “type or namespace name ‘Collection’ could not be found.”

I am new to generics so I dont know what Im doing wrong.

Collection<[COLOR=blue]string[/COLOR]> people = [COLOR=blue]new[/COLOR] Collection<[COLOR=blue]string[/COLOR]>();

That is the line that the compiler has trouble with.

Im not 100% sure, (because I too am learning), but I dont think “Collection” is a valid class, let alone a valid generic class (Unless you wrote a class called Collection). Make sure you have the “System.Collections.Generic” reference, and you could use something like “List<>”…

List<[COLOR="Blue"]string[/COLOR]> people = new List<[COLOR="blue"]string[/COLOR]>();

Hope that helps.

^Learning is fun :fab:

You forgot the namespace.

using System.Collections.ObjectModel;

Ah yes. Thank you. I thought I was supposed to add the System.Collections reference, but such thing did not exist. :slight_smile:

You should always have the

Using System.Collections;

But you would then add the other one below it.

using System.Collections;
using System.Collections.ObjectModel;

yay, i learned something as well! =)

If you right-click on Collection, there should be a menu-item called Resolve that will take care of this for you automatically (unless the actual reference itself isn’t there) :slight_smile:

Yeah usually it pops up with a squiggly line under the error and will pop up a suggestion box when you hover on this squiggly line usually giving you the namespaces with the most similar sounding items in with the one you want at the top.

Of course if it already knows what you are talking about why does it need the imports statement :D?!?!?!

^I believe only vb.net does this.

Oh, fair enough :stuck_out_tongue: I program in .NET at work because noone knows C/C++ and they don’t really want the headache of learning a new syntax so I’ve not really used c#

Of course I do accidentally add braces and semicolons to the end of my .NET code sometimes :smiley: