IOrderedenumerable.range用法<TSource>OrderBy怎么用

&nbsp&怎么用_百度知道
&nbsp&怎么用
我有更好的答案
只有这种用法:& 在HTML中表示空格
其他类似问题
为您推荐:
您可能关注的推广
amp的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁c# - Resolving extension methods/LINQ ambiguity - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I'm writing an add-in for
4. For this, I needed to reference several of ReSharper's assemblies. One of the assemblies (JetBrains.Platform.ReSharper.Util.dll) contains a System.Linq namespace, with a subset of extension methods already provided by System.Core.
When I edit the code, it creates an ambiguity between those extensions, so that I cannot use OrderBy, for instance. How could I solve this? I would like to use the core
extensions, and not the ones from ReSharper.
I get the following error when trying to compile:
The call is ambiguous between the
following methods or properties:
'System.Linq.Enumerable.OrderBy&string,int&(System.Collections.Generic.IEnumerable&string&,
System.Func&string,int&)' and
'System.Linq.Enumerable.OrderBy&string,int&(System.Collections.Generic.IEnumerable&string&,
System.Func&string,int&)'
EDIT: I tried the suggestion below, unfortunately without luck. In the meanwhile, I "solved" the problem by removing references to System.Core. This way I could use the extensions provided by ReSharper DLL files.
where I just imported the ReSharper DLL files I needed. I changed the alias of System.Core to SystemCore, added the extern alias directive, but it still didn't work. If I missed something, please let me know.
P.S. The references are to ReSharper v4.1 DLL files installed in the default directroy in "C:\Program Files\JetBrains\ReSharper\v4.1\...".
9,669126799
22.1k1258120
This is probably one of those rare cases where it makes sense to use an .
In the properties page for the reference to System.Core (i.e. under References, select System.Core, right-click and select "Properties"), change the "Aliases" value to "global,SystemCore" (or just "SystemCore" if it's blank to start with).
Then in your code, write:
extern alias SystemC
using SystemCore::System.L
That will make all the relevant types etc in System.Core.dll's System.Linq namespace available. The name "SystemCore" here is arbitrary - you could call it "DotNet" or something else if that would make it clearer for you.
868k46262137240
This isn't really an answer, but may provide an easier way for others to reproduce the issue (from the command-line - you could do it with two projects in Visual Studio if you want).
1) Create BadLinq.cs and build it as BadLinq.dll:
using System.Collections.G
namespace System.Linq
public static class Enumerable
public static IEnumerable&T& Where&T&(this IEnumerable&T& source,
Func&T,bool& predicate)
2) Create Test.cs:
extern alias SystemC
using SystemCore::System.L
static class Test
static void Main()
var names = new[] { "Larry", "Curly", "Moe" };
var result = names.Where(x =& x.Length & 1);
3) Compile Test.cs specifying the extern alias:
csc Test.cs /r:BadLinq.dll /r:SystemCore=System.Core.dll
This fails with:
Test.cs(11,28): error CS1061:
'System.Array' does not contain a
definition for 'Where' and no
extension method 'Where' accepting a first argument of type
'System.Array' could be found
(are you missing a using directive or an assembly reference?)
If you change it to not try to use an extension method (i.e. Enumerable.Where) it works fine with the extern alias.
I think this may be a compiler bug. I've emailed a private mailing list which the C# team reads - I'll update this answer or add a new one when I hear back.
868k46262137240
This is no longer an issue, since I am able to use the LINQ extensions, as provided by ReSharper DLL files, even while targeting .NET 3.0.
Mr. Skeet was right again! I am able to use full LINQ syntax, while targeting .NET 3.0 in the project's properties and not referencing System.Core!
9,669126799
22.1k1258120
In order for ReSharper to be as compatible as possible with the variety of solutions it is used with, it is built against .NET 2.0. LINQ, etc. came in in C# 3.0, so they are not available in that version of the Framework. So, JetBrains added in their own version.
The solution is to build your addin against .NET 2.0 as well.
9,669126799
One solution would be to move all your code out to a partial class that uses the ReSharper code. In there, you'd import only the ReSharper namespace and not System.Core.
In the rest of the partial class, you'd import all the other namespaces you need, including System.Core, but not the ReSharper namespace.
9,669126799
2,20921621
I had the same problem, even with extern alias, and I
on Connect. The workaround for the time being is to forgo the extension method syntax.
The bug is fixed for Visual&Studio&2010.
9,669126799
It is really a compiler error.
I had the same problem, and I solved it just by cleaning and rebuilding the project. After that the problem disappeared.
9,669126799
I had the ambiguous reference problem ponentModel. Visual Studio was complaining that a DLL file exists in both v2 and v4. I was able to resolve it by removing the reference to the System DLL file and readding it.
9,669126799
I had a similar situation. After two hours struggling I realized I had duplicate namespace names in my libraries. If you are using file Dynamic.cs published by Microsoft, the only thing you need to do is rename the current namespace to something else, and it will be fixed.
//Copyright (C) Microsoft Corporation.
All rights reserved.
using System.Collections.G
using System.T
using System.L
using System.Linq.E
using System.R
using System.Reflection.E
using System.T
namespace System.Linq.Dynamic
&- for example to Linq.Dynamic
9,669126799
I found this same sort of ambiguity when use PagedList in MVC (.Net 4.5, MVC 5). I found that if I took the object for the argument that was ambiguous and cast it explicitly first, the problem was resolved. To if the ambiguity was between a method that takes System.Linq.Enumerable and one that takes System.Collections.Generic.IEnumerable as the parameter in question, and the source is of type System.Collections.Generic.IEnumerable, I don't use the extension method on it. I cast it.In this example, my repository method returns a List:
searchRequest.CaseSearchResults = csr.SelectMatchingCases(searchRequest);
var results = searchRequest.CaseSearchResults.AsEnumerable&CaseSearchResult&();
int pageNum = (int)(ViewBag.PageNum ?? 1);
var pageResults =results.ToPagedList&CaseSearchResult&(pageNum, 5);
Calling the extension method on searchRequest.CaseSearchResults caused explicitly casting to results and then calling the extension on that worked.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled初中三年级课文中&傅雷家书两则&贯穿了一种怎样的内在精神
熙の支援132
尽管这两封家书内容不太一样,但是其中都贯穿了一种作者倡导的坚强的精神.这种坚强的精神可以从两个方面来理一是在遇到困难时,要不怕失败,不怕挫折,不怕打击;二是在取得成功时,要戒骄戒躁,争取更大的成功.
为您推荐:
其他类似问题
扫描下载二维码其他回答(1)
this IEnumerable&TSource& source 是指该方法为一个扩展方法,凡是IEnumerable&TSource&类型的对象都可以调用OrderBy&TSource, TKey&方法。
Func&TSource, TKey& keySelector是一个委托,TSource是委托的参数类型,TKey为委托的返回类型。
以下代码来自
public string Name { get; set; }
public int Age { get; set; }
public static void OrderByEx1(System.Windows.Controls.TextBlock outputBlock)
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
IEnumerable&Pet& query = pets.OrderBy(pet =& pet.Age);
foreach (Pet pet in query)
outputBlock.Text += "\n" + String.Format("{0} - {1}", pet.Name, pet.Age);
This code produces the following output:
Whiskers - 1
Barley - 8
园豆:3591
class Pet&&&&&&&&&&& {&&&&&&&&&&&&&&& public string Name { get; set; }&&&&&&&&&&&&&&& public int Age { get; set; }&&&&&&&&&&& }&&&&&&&&&&& public static void OrderByEx1()&&&&&&&&&&& {&&&&&&&&&&&&&&& Pet[] pets = { new Pet { Name="Barley", Age=8 },&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& new Pet { Name="Boots", Age=4 },&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& new Pet { Name="Whiskers", Age=1 } };&&&&&&&&&&&&&&& IEnumerable&Pet& query = pets.OrderBy(pet =& pet.Age);&&&&&&&&&&&&&&& foreach (Pet pet in query)&&&&&&&&&&&&&&& {&&&&&&&&&&&&&&&&&&& Console.WriteLine("{0} - {1}", pet.Name, pet.Age);&&&&&&&&&&&&&&& }&&&&&&&&&&& }&&&&&&&&&&& /*&&&&&&&&&&&& This code produces the following output:&&&&&&&&&&&& Whiskers - 1&&&&&&&&&&&& Boots - 4&&&&&&&&&&&& Barley - 8&&&&&&&&&&& */
&&&您需要以后才能回答,未注册用户请先。}

我要回帖

更多关于 enumerable 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信