使用Linq通话是模棱两可的错误

编程入门 行业动态 更新时间:2024-10-11 17:23:25
本文介绍了使用Linq通话是模棱两可的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先,对不起的通用名称类感到抱歉.我的雇主很偏执,我知道他在这个网站上漫游.好的,所以我有以下代码:

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通话是模棱两可的错误

本文发布于:2023-10-18 04:21:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模棱两可   错误   Linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!