Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • 2 years later...
Posted

If you are using .NET 3.5 and have access to LINQ, you might make use of something like this:

 

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

var distinct = Enumerable.Distinct(x);

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...