Sunday, March 31, 2013

Convert a Comma Delimited String to an Dictionary in C#

Here i will show how to Convert a Comma Delimited String to an Dictionary in C#
In the previous post i had shown u how to get all selected values from ListBox
continuing the above link.....



string Val = "a,b,c,d,e";

Dictionary<string, string> MyDict1 = new Dictionary<string, string>();

MyDict1 = Val.Split(',').ToDictionary(key => key.Trim(), value => value.Trim());

Out Put :

a -> a
b -> b
c -> c
d -> d
e -> e 

No comments:

Post a Comment