# [.net] std::map equivalent

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there an equivalent for std::map in .NET?

##### Share on other sites
Is it SortedList? It seems to be the most like it...

##### Share on other sites
In .NET 1.x:
System.Collections.Hashtable

System.Collections.Generic.Dictionnary<K, T>

Look it up.
jods

##### Share on other sites
I don't think a hastable would work, because I am working with value types for the keys. I had some trouble getting it working, but maybe that is because of something else that I did wrong.

Generic Dictionary: I cannot use 2.0, but thank you all the same .

##### Share on other sites
I think I am right. Look at this:

using System;namespace Testing{	struct Point	{		public Point(int x, int y)		{			this.x = x;			this.y = y;		}		public int x;		public int y;	}	public class MainClass	{		public static void Main()		{			Point p1 = new Point (10, 10);			Point p2 = new Point (10, 20); // Note the 20			Console.WriteLine(p1.GetHashCode() + " " + p2.GetHashCode());		}	}}

The output is "10 10", so I don't think it could be used correctly with a HashTable.

##### Share on other sites
I really don't see a problem. Just override GetHashCode(). I never noticed a problem using Hashtable (aside from the fact you have to box/unbox) on value types.

##### Share on other sites
Meh, I don't want to go through the trouble of that for what I am trying to do (how lazy can a guy be? :P). I think I will just simulate what I am trying to do by using two parallel ArrayLists.

##### Share on other sites
Nope, my last idea won't work.

What I am trying to do related to A*.

I want to check to see if one of my open nodes shares the same coords as the current node which I am going to add to the open list. I guess I will have to loop throught it.

##### Share on other sites
Then just use a sorted list of points and use Contains(). (And you don't have to write your own Point class as .NET already has it.)

##### Share on other sites
Thanks, there is a point class! It's in System.Drawing, so when I convert this to GDI I'll use it. As of now, I don't know how use the namespace (intellisense can't find it).

I could use a sorted list, but then the values wouldn't be sorted (and I need them to be able to). I think my way will work fine (using a foreach), but if it doesn't I will try your method.

Again, thank you for your time.

1. 1
2. 2
frob
15
3. 3
4. 4
5. 5

• 14
• 13
• 14
• 69
• 22
• ### Forum Statistics

• Total Topics
632138
• Total Posts
3004319

×