tags:

views:

217

answers:

3

hello.

I want to use HashSet in my program.

but I couldn't declare HashSet.

My Computer was installed Microsoft .Net FrameWork 3.5.

and also I declared namespace. (using System.Collections.Generic)

But It didn't work.

How i fix this problem?

i am use visual studio 2005(c#) and Windows 7.

thanks.

A: 

The <T> means that a hashset is a hashset of a particular type. So for example, you could have a HashSet<String> or a HashSet<Integer> etc. and you have to declare it as such.

(I'm coming from a Java background but I'm 97% sure it's pretty much the same in C#).

MatrixFrog
Hi, MatrixFrog.Thank you for your answer. But I Know that.It means I can't declare HashSet<T> type variables.for example, HashSet<string> temp; <- It didn't work.
inchury
Probably not really the problem. He needs to reference a specific assembly, which doesn't happen automatically with that old version of Visual Studio.
codekaizen
+5  A: 

"i am use visual studio 2005(c#) and Windows 7."

Then you're not using .Net 3.5. You need to specifically reference the System.Core assembly in your project.

codekaizen
Thank you for you help.It was fixed.
inchury
@inchury: glad to help. Feel free to mark this as the answer.
codekaizen
A: 

Its pretty much the same as java. The only difference is that EVERYTHING inherits from object in c# (even primitives like 'string','int',etc...). Meaning, declare it as:

HashSet<string> rather than HashSet<String>
jdc0589
Probably not really the problem. He needs to reference a specific assembly, which doesn't happen automatically with that old version of Visual Studio.
codekaizen
string and String is the same thing in C#. You might confuse this with Java's boxed types (int vs. Integer).
Benjamin Podszun
Also, string isn't a primitive type.
Jon Skeet
I know, I meant to say it just looks like a primitive to someone coming from java. Poor phrasing on my part.
jdc0589