jjzjj

generic-method

全部标签

c# - 如何: Use async methods with LINQ custom extension method

我有一个LINQ自定义扩展方法:publicstaticIEnumerableDistinctBy(thisIEnumerableitems,Funcproperty){returnitems.GroupBy(property).Select(x=>x.First());}我是这样使用它的:varspc=context.pcs.DistinctBy(w=>w.province).Select(w=>new{abc=w}).ToList();但问题是我不想要ToList()我想要这样的东西varspc=awaitcontext.pcs.DistinctBy(w=>w.province).

c# - 错误 CS0051(不一致的可访问性 : parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)' )

我通过省略totalFee字段成功编译并运行了下面的源代码。如何将totalFee写入此程序,以便它准确计算每项工作的总费用(费率*时间)?下面,您会看到我尝试使用一种方法;这产生了错误CS0051(可访问性不一致:参数类型“Job”的可访问性低于方法“AddJobs.TotalPay(Job)”)。此源代码是对以下作业的响应:"DesignaJobclassforHarold’sHomeServices.Theclasscontainsfourdatafields—Jobdescription(forexample,“washwindows”),timeinhourstocomple

c# - 可访问性不一致 : return type is less accessible than method C#

好吧,这真的很奇怪。我有一个私有(private)成员,我想将它用于Form2。我创建了一个公共(public)静态方法,以便我可以将该成员放入Form2。这是我的代码:privatestaticAppControllerappController;privateBreadRepositorybreadRep;privateCakeRepositorycakeRep;privateSandwichRepositorysandwichRep;publicForm1(){InitializeComponent();breadRep=newBreadRepository();cakeRep=

c# - 如何关闭 resharper 中的 "Convert Extension Method to Plain Static"自动重构?

在使用Resharper时,由于某些原因,当我调用扩展方法时,它会自动将其转换为静态方法调用。这就是所谓的ConvertExtensionMethodtoPlainStatic重构。foo.Bar()成为MyStaticExtensions.Bar(foo);具有讽刺意味的是,它随后将此标记为代码异味。我该如何关闭它? 最佳答案 Resharper的IntelliSense中嵌入了此功能。我经常使用Linq-to-sql扩展,所以我禁用了这个功能:Resharper-选项-IntelliSense-启用RadiobuttonVisu

c# - 为什么具有 "where T : class"约束的 Generic<T> 方法接受接口(interface)

我有这个interface:publicinterfaceITestInterface{intTestInt{get;set;}}和这个通用方法(带有T:class约束):publicvoidTest()whereT:class{//DoSomething}这个电话:Test();一切都编译并运行,同时interface不是class(或者是吗?)。为什么会这样?我第一次看到这个是在我的WCF代理类上:publicpartialclassTestServiceClient:System.ServiceModel.ClientBase,TestNamespace.ITestService

c# - System.Collections.Generic.List<T> 需要 '1' 类型参数

我在以下代码中遇到此错误:string[]colors={"green","brown","blue","red"};varlist=newList(colors);IEnumerablequery=list.Where(c=>c.length==3);list.Remove("red");Console.WriteLine(query.Count());此外,Count()似乎不再被允许。它被弃用了吗? 最佳答案 您正在尝试创建一个List你应该告诉编译器varlist=newList(colors);没有List,有一个名为Li

c# - 如何修复 'compiler error - cannot convert from method group to System.Delegate' ?

publicMainWindow(){CommandManager.AddExecutedHandler(this,ExecuteHandler);}voidExecuteHandler(objectsender,ExecutedRoutedEventArgse){}错误1​​参数2:无法从“方法组”转换为“System.Delegate” 最佳答案 我猜有多个具有不同签名的ExecuteHandler。只需将您的处理程序转换为您想要的版本:CommandManager.AddExecuteHandler(this,(Action)

c# - 为什么这段代码会提示 "the arity of the generic type definition"?

我有一个通用类型:classDictionaryComparer:IEqualityComparer>还有一个工厂方法,它将(应该)为给定的字典类型创建此类的实例。privatestaticIEqualityComparerCreateDictionaryComparer(){Typedef=typeof(DictionaryComparer);Debug.Assert(typeof(T).IsGenericType);Debug.Assert(typeof(T).GetGenericArguments().Length==2);Typet=def.MakeGenericType(ty

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

C# "Method not found"未使用反射的运行时异常

我在获取上述异常时遇到问题。我有一个相对简单的结构,分为两个dll。第一个包含一个IEntityService,IEntity,具有基本的实现。第二个包含实际的实现和接口(interface)。所以有一个实现IEntityService的IMachine服务和实现IEntityService和EntityService的MachineService。结果集合(实体加服务)也会发生类似的情况。此外,服务(机器和结果)是部分类/接口(interface),其中一个类是自动生成的。现在,在其中一台ResultMachine中,我试图获得一台机器,如果它不存在,我将创建它并保存。但是,当我尝试