SyntaxHighlighter

Friday, March 9, 2007

Converting Collections in .NET 2.0

So last night I was having a bit of an issue with getting the values from my Dictionary<string,int> to a normal generic List<int>.

I figured it out and just knew their had to be a better way, so I asked a co-worker of mine the next morning and got the following result after collaborating with him... of course the results were much better this time around.



As you can see from above I just pass the values from the dictionary to the constructor of the collection I want to convert to. I am able to do this because the constructor takes IEnumerable as a parameter... any collection which inherits IEnumerable can be passed in.
In the future always look for this first, for it may be the solution your looking for when converting collection in .NET 2.0

No comments:

Post a Comment