471,350 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

unique list, set

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?
Jan 7 '06 #1
2 13136

"Someone" <no****@nospam.com> wrote in message
news:dp**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
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.
Jan 7 '06 #2
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]
- mv*@spam.guard.caspershouse.com

"Mike Schilling" <ms*************@hotmail.com> wrote in message
news:us*************@TK2MSFTNGP11.phx.gbl...

"Someone" <no****@nospam.com> wrote in message
news:dp**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
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.

Jan 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by kevin parks | last post: by
5 posts views Thread by Roy Smith | last post: by
3 posts views Thread by David Berry | last post: by
22 posts views Thread by Claudio Jolowicz | last post: by
9 posts views Thread by Brian Tkatch | last post: by
5 posts views Thread by Greg Corradini | last post: by
8 posts views Thread by Marc | last post: by
reply views Thread by Gabriel Genellina | last post: by
5 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.