首先,对不起的通用名称类感到抱歉.我的雇主很偏执,我知道他在这个网站上漫游.好的,所以我有以下代码:
First of all, sorry for excesive generic name classes. My employer is paranoid and I know for sure he roams this site. Ok, so I have this code:
var fooObj = new MyFooClass() { fooField1 = MyEnum.Value3, fooField2 = false, fooField3 = false, fooField4 = otherEntity.OneCollection.ElementAt(0) as MyBarClass }其中otherEntity.OneCollection是ISet. ISet是实现IEnumerable的NHibernate集合类.如果我尝试编译此代码,则会收到此错误:
where otherEntity.OneCollection is an ISet. ISet is a 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)'但是,如果我在课程开始时删除了使用System.Linq并将代码更改为此:
But if I remove the using 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 }它可以编译和运行. (?操作员为了清楚起见检查OneCollection是否已删除元素)
it compiles and works. (? operator to check if OneCollection has elements removed for the sake of clarity)
有人可以向我解释这个错误吗?
Could anyone explain this error to me?
在相关的情况下:我正在使用Visual Studio 2008,目标是.NET Framework 3.5,并使用ReSharper 5.1.
In case is relevant: I'm using Visual Studio 2008, targeting .NET Framework 3.5 and using ReSharper 5.1.
注意.-编辑以澄清该集合是哪个具体的IEnumerable,对此表示歉意.
NOTE.- Edited to clarify which concrete IEnumerable is the collection, sorry for that.
推荐答案这很奇怪.
该错误声称两个完全相同的签名之间存在歧义.
The error claims that there's an ambiguity between two completely identical signatures.
我唯一能想到的是,您可能以某种方式弄乱了项目中的引用",并且可能同时引用了"System.Core 3.5"和"System.Core 3.5.0.1"(人为的例子)..在这种情况下,您会得到这样的错误,但是,我无法想到为什么System.Linq.Enumerable.ElementAt(otherEntity.OneCollection起作用-它应该报告相同的问题.
The only thing I can think of is that you might somehow have the 'references' messed up in your project and that maybe you have i.e. reference both to 'System.Core 3.5' and 'System.Core 3.5.0.1' (contrived example).. You would get such error in this case, but yet, I cannot think why System.Linq.Enumerable.ElementAt(otherEntity.OneCollection works - it should report the same problem.
..还是您以某种邪恶的方式使您的"OneCollection"两次实现了IEnumerable?但是,我认为错误消息会有所不同.
.. or maybe you somehow made your 'OneCollection' implement the IEnumerable twice in some wicked way? But then, I think the error message would be different.
更多推荐
使用Linq通话是模棱两可的错误
发布评论