草庐IT

method-group

全部标签

c# - VB.NET linq group by 匿名类型不能按预期工作

我正在研究LINQPad附带的一些linq示例。在“C#3.0inaNutshell”文件夹中的Chater9-Grouping下,有一个名为“GroupingbyMultipleKeys”的示例查询。它包含以下查询:fromninnew[]{"Tom","Dick","Harry","Mary","Jay"}.AsQueryable()groupnbynew{FirstLetter=n[0],Length=n.Length}我将字符串“Jon”添加到数组的末尾以获得实际分组,并得出以下结果:这正是我所期待的。然后,在LINQPad中,我转到同一查询的VB.NET版本:'Manuall

c# - 通过安装程序设置模拟属性会导致 'Expression is not a method invocation'

我有下面的代码,其中我的Mock接口(interface)有一个Recorder属性,它是一个类。然后我尝试在该类上设置一个属性,但我得到了一个Expressionisnotamethodinvocation错误。你能帮忙吗?错误是在运行时尝试设置枚举属性时出现的。它会抛出一个带有以下堆栈跟踪的ArgumentException:atMoq.ExpressionExtensions.ToMethodCall(LambdaExpressionexpression)atMoq.Mock.c__DisplayClass1c`2.b__1b()atMoq.PexProtector.Invoke

C# 错误 : The call is ambiguous between the following methods or properties. 运算符重载

我在名为Dinero的命名空间中有2个带有重载运算符的类,这些是2个类:第一个:namespaceDinero{classDollar{#regionAtributospublicDoublecant;#endregion#regionConstructorespublicDollar(){this.cant=0;}publicDollar(Doubleamount){this.cant=amount;}#endregion#regionSobrecargadeOperadorespublicstaticDollaroperator+(Euroeu,Dollardol){Dollard

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# - 方法推断不适用于方法组

考虑voidMain(){varlist=new[]{"1","2","3"};list.Sum(GetValue);//errorCS0121list.Sum(s=>GetValue(s));//works!}doubleGetValue(strings){doubleval;double.TryParse(s,outval);returnval;}CS0121错误的描述是Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Linq.Enumerable.Sum(System.Collections.Gen

c# - Entity Framework : Efficiently grouping by month

我对此做了一些研究,到目前为止我发现的最好的方法是在整个数据集上使用Asenumerable,以便在对象的linq中而不是在数据库中进行过滤。我使用的是最新的EF。我的工作(但非常慢)代码是:vartrendData=fromdinExpenseItemsViewableDirect.AsEnumerable()groupdbynew{Period=d.Er_Approved_Date.Year.ToString()+"-"+d.Er_Approved_Date.Month.ToString("00")}intogselectnew{Period=g.Key.Period,Total=

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# - 为什么 C# LINQ 表达式必须以 Select 或 Group By 子句结尾,而在 VB.Net 中没有这样的限制

由于我的标题是不言自明的,我知道如何纠正它,但首先为什么会这样?场景我写了一个VB.Net代码DimlistAsList(OfString)=NewList(OfString)//CodetopopulatelistDimwherelinqAsIEnumerable(OfString)=FromsInlistWheres.StartsWith("A")这工作正常,没有错误但在C#中同样的逻辑失败了Listlist=newList();//CodetopopulatelistIEnumerablewherelinq=fromsinlistwheres.StartsWith("A");这给

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

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