Linq questions

C

CSharper

Yesterday I was working on a code where I need to split the parameters
and create dictionary from it. The string is something like the
following

name key1=value1 key2=value2

here is the code

string[][] pharsed = argument.Skip(1).Select(s =>
s.split(’=')).ToArray();

IDictionary<string, string> dictionary = new Dictionary<string,
string>();

foreach(string[] vaue in pharsed)

{

dictionary.add(vaue[0], vaue[1]);

}

Just want to know, is it possible to create the dictionary also in the
same line of code instead of doing it like I am trying?

http://myfavoritemovies.us/csharp/?p=21
 
I

Ignacio Machin ( .NET/ C# MVP )

Yesterday I was working on a code where I need to split the parameters
and create dictionary from it. The string is something like the
following

name key1=value1 key2=value2

here is the code

string[][] pharsed = argument.Skip(1).Select(s =>
s.split(’=')).ToArray();

IDictionary<string, string> dictionary = new Dictionary<string,
string>();

foreach(string[] vaue in pharsed)

{

     dictionary.add(vaue[0], vaue[1]);

}

Just want to know, is it possible to create the dictionary also in the
same line of code instead of doing it like I am trying?

http://myfavoritemovies.us/csharp/?p=21

Hi,

How do you separate between a value and the next keyname?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top