a1jit Posted July 25, 2006 Posted July 25, 2006 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. Quote
TaleOfTimes Posted November 3, 2008 Posted November 3, 2008 Here is a link on how to use predicates: http://msdn.microsoft.com/en-us/library/bfcke1bz(VS.80).aspx Just think of it as a Comperator, except you're only using a method. Quote
Nate Bross Posted November 3, 2008 Posted November 3, 2008 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); Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.