What is wrong with the below statement(C#3.0 / Lambda)

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-12T03:28:03Z Indexed on 2010/05/12 3:34 UTC
Read the original article Hit count: 125

Filed under:
|

what is wrong in the below

Enumerable.Range(0, objEntityCode.Count - 1).Select(i => 
{ 
options.Attributes[i] = new EntityCodeKey 
{ 
EntityCode = objEntityCode[i].EntityCodes 
, OrganizationCode = Constants.ORGANIZATION_CODE }; 
})
.ToArray(); 

Throwing 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.

But this works

Enumerable.Range(0, objEntityCode.Count - 1).ToList().ForEach(i =>  
                { 
                    options.Attributes[i] = new EntityCodeKey 
                    { 
                         EntityCode = objEntityCode[i].EntityCodes 
                         , OrganizationCode = Constants.ORGANIZATION_CODE   
                    };  

                } 
             ); 

Using C#3.0.

Purpose: I am learning LINQ / LAMBDA and trying to do the same program in different way.

Thanks.

© Stack Overflow or respective owner

Related posts about c#3.0

Related posts about homework