unique list, set

  • Thread starter Thread starter Someone
  • Start date Start date
S

Someone

Hi,

What sort of data structures does c# have to create a set. Java allows you
to create a set, just wondering what I can use in c#. Will I be forced to
implemented custom code?
 
Someone said:
Hi,

What sort of data structures does c# have to create a set. Java allows
you
to create a set, just wondering what I can use in c#. Will I be forced to
implemented custom code?

Do what Java does, which is to base a Set on a Map (or as .NET 1.1 calls it,
Hashtable)

public class HashSet
{
Hashtable tbl = new Hashtable;

public void Add(Object o)
{
tbl[o] = tbl;
}

public bool Contains(Object o)
{
return tbl[o] != null;
}
}

etc.
 
Additionally, in .NET 2.0, you can use the Dictionary<TKey, TValue>
class, which will allow you to use type-safe maps.


Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mike Schilling said:
Someone said:
Hi,

What sort of data structures does c# have to create a set. Java allows
you
to create a set, just wondering what I can use in c#. Will I be forced
to
implemented custom code?

Do what Java does, which is to base a Set on a Map (or as .NET 1.1 calls
it, Hashtable)

public class HashSet
{
Hashtable tbl = new Hashtable;

public void Add(Object o)
{
tbl[o] = tbl;
}

public bool Contains(Object o)
{
return tbl[o] != null;
}
}

etc.
 
Back
Top