First of all, sorry for the excesive generic name classes. My employer is paranoid, and I know for sure that he roams this site. So, I have this code:
var fooObj = new MyFooClass()
{
fooField1 = MyEnum.Value3,
fooField2 = false,
fooField3 = false,
fooField4 = otherEntity.OneCollection.ElementAt(0) as MyBarClass
}
where otherEntity.OneCollection is an ISet. ISet is an NHibernate collection class that implements IEnumerable. If I try to compile this code, I get this error:
Error 2 The call is ambiguous between the following methods or properties:
'System.Linq.Enumerable.ElementAt<MyFirm.Blah.Blah.ClassyClass> (System.Collections.Generic.IEnumerable<MyFirm.Blah.Blah.ClassyClass>, int)'
and
'System.Linq.Enumerable.ElementAt<MyFirm.Blah.Blah.ClassyClass>(System.Collections.Generic.IEnumerable<MyFirm.Blah.Blah.ClassyClass>, int)'
But if I remove the use of System.Linq at the beginning of the class and change the code to this:
var fooObj = new MyFooClass()
{
fooField1 = MyEnum.Value3,
fooField2 = false,
fooField3 = false,
fooField4 = System.Linq.Enumerable
.ElementAt(otherEntity.OneCollection, 0) as MyBarClass
}
It compiles and works. (?) to check if OneCollection elements are removed for clarity)
Can someone explain this error to me?
In case of relevance: I am using Visual Studio 2008, targeting the .NET Framework 3.5 and using ReSharper 5.1.
. - , , IEnumerable , .