The collection supporting uniqueness is, for example
System.Collections.Generic.Dictionary<KEY, VALUE>
; please see:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[
^].
The method
TryGetValue
can make you get a value indexed by some key or an information if it is already in a dictionary; and the methods
ContainsKey
(this one if very fast, of nearly O(1) complexity) and
ContainsValue
(can be slow) will check up what is there. You can keep all your values in parallel with the values in the control and check/add new values before adding them to UI.
Look at other generic collection types and read MSDN help pages on each to know when to use one or another:
http://msdn.microsoft.com/en-us/library/0sbxh9x2.aspx[
^].
Now, about
ArrayList
. First, there is no need to use it for any new development. Instead, use
System.Collections.Generic.List<T>
:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[
^].
All non-specialized non-generic collection types were rendered obsolete in the .NET Framework v.2.0, when generics were introduced. They are fine if they already work in fully-debugged legacy units, but using then in new development makes absolutely no sense, as they require less safe type casting. Generics were invented to eliminate those type casts. If you are not well familiar with generics, perhaps this is the first thing to read about right now.
But — the list type won't help you. The question about using the list to represent relations makes no sense, really. A list can represent only a list. You have to work with the Cartesian Square objects and the subsets of it which represent an arbitrary finite graph or a relation. As a simplest way to represent a Cartesian Square
A x A
you could simple use an array
[N, N]
, where
N
represents a number of elements in the set, such as a set of the noted of a graph. I have more or less comprehensive explanation of representation of graphs and relations in my article:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[
^].
Please see the section "3.6 Cartesian Square":
Enumeration Types do not Enumerate! Working around .NET and Language Limitations [
3.6. Cartesian Square].
See also:
http://en.wikipedia.org/wiki/Cartesian_product[
^],
http://en.wikipedia.org/wiki/Binary_relation[
^].
—SA