まず、総称名クラスが多すぎてすみません。私の雇用主は偏執的で、彼がこのサイトを歩き回っていることは確かです。さて、私はこのコードを持っています:
var fooObj = new MyFooClass()
{
fooField1 = MyEnum.Value3,
fooField2 = false,
fooField3 = false,
fooField4 = otherEntity.OneCollection.ElementAt(0) as MyBarClass
}
ここで、otherEntity.OneCollection は ISet です。ISet は、IEnumerable を実装する NHibernate コレクション クラスです。このコードをコンパイルしようとすると、次のエラーが発生します。
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)'
しかし、クラスの先頭にある using System.Linq を削除し、コードを次のように変更すると:
var fooObj = new MyFooClass()
{
fooField1 = MyEnum.Value3,
fooField2 = false,
fooField3 = false,
fooField4 = System.Linq.Enumerable
.ElementAt(otherEntity.OneCollection, 0) as MyBarClass
}
コンパイルして動作します。(? わかりやすくするために OneCollection に要素が削除されているかどうかを確認する演算子)
誰かが私にこのエラーを説明できますか?
関連するケース: Visual Studio 2008 を使用し、.NET Framework 3.5 を対象とし、ReSharper 5.1 を使用しています。
注.-具体的なIEnumerableがコレクションであることを明確にするために編集されました。申し訳ありません。