Problem in populating a dictionary object using Enumerable.Range() (C#3.0)

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-03T10:54:43Z Indexed on 2010/05/03 10:58 UTC
Read the original article Hit count: 143

Filed under:

If I do

        for (int i = 0; i < appSettings.Count; i++)
        {

            string key = appSettings.Keys[i];

            euFileDictionary.Add(key, appSettings[i]);

        }

It is working fine.

When I am trying the same thing using

Enumerable.Range(0, appSettings.Count).Select(i =>
            {
                string Key = appSettings.Keys[i];
                string Value = appSettings[i];
                euFileDictionary.Add(Key, Value);
            }).ToDictionary<string,string>();

I am getting a compile time error

The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Any idea?

Using C#3.0

Thanks

© Stack Overflow or respective owner

Related posts about c#3.0