Using List Exists Method in C#

a1jit

Regular
Joined
Aug 19, 2005
Messages
89
I am having a problem doing the following in generics.

I have one custom type array. Its a struct with few elements in it like id, shortname, longname

Sample data would be
1, a, australia
2, a, asia
3, b, bangkok

The problem im facing is that i want to actually gather all unique shortname
and place it in another List (generic)

I plan to create another new List, and then check whether the
element exists in the new List, if not add it, else, move to the next item

So i plan to make use of the Exists method in generic (List) but
seems like im not sure how to use it since it has predicate.

I hope the above explanation makes sense.

Does anyone have some idea of how I might go about this? Any help
(particularly example code) would be much appreciated.
 
If you are using .NET 3.5 and have access to LINQ, you might make use of something like this:

C#:
var x = from struct s in genericList
                            select s.ShortName;

var distinct = Enumerable.Distinct(x);
 
Back
Top