草庐IT

method-group

全部标签

c# - 多线程,Task.Run 错误 'The call is ambiguous between the following methods or properties'

当我尝试构建项目时,显示以下错误消息。Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Threading.Tasks.Task.Run(System.Action)'and'System.Threading.Tasks.Task.Run(System.Func)'我该如何解决这个问题?publicstaticclassMaintananceManager{privatestaticThreadSafeSocialMediaListPostList=newThreadSafeSocialMediaList(

c# - 如何初始化 ConcurrentDictionary?错误 : "Cannot access private method ' Add' here"

我有一个静态类,我在其中使用字典作为查找表以在.NET类型和SQL类型之间进行映射。这是一个这样的字典的例子:privatestaticreadonlyDictionarySqlServerMap=newDictionary{{typeof(Boolean),"bit"},{typeof(Byte[]),"varbinary(max)"},{typeof(Double),"float"},{typeof(Byte),"tinyint"},{typeof(Int16),"smallint"},{typeof(Int32),"int"},{typeof(Int64),"bigint"},{

C# 方法组奇怪

我发现了一些非常奇怪的东西,我希望能更好地理解它。varall=newList{newint[]{1,2,3},newint[]{4,5,6},newint[]{7,8,9}};all.ForEach(n=>n.ForEach(i=>Console.WriteLine(i)));可以重写为:...all.ForEach(n=>n.ForEach(Console.WriteLine));怎么可能省略lambda表达式参数(i=>)而仍然将当前项目传递给console.WriteLine?感谢任何见解。-基思 最佳答案 List.For

c# - Visual Studio Community 2015 调试器在带有 "Evaluation of native methods is not supported"的条件断点处结束 - 如何修复?

我有一个条件断点,条件检查字符串的值,如果为真则停止。它停止了,但随后打开一个窗口说:断点的条件无法执行...返回的错误是“评估方法System.Collections.Specialized.NameValueCollection.get_Item()调用native方法”System.Globalization.TextInfo.Internal.GetCaseInsHash().不支持在此上下文中评估native方法。'。单击“确定”在此断点处停止。我搜索了答案,但他们说启用托管兼容模式,但没有用。 最佳答案 在项目调试设置下

c# - 使用C#方法组执行代码

在更新我的UI代码(.NET4.0应用程序中的C#)时,由于在错误的线程中执行对UI的调用,我遇到了奇怪的崩溃。然而,我已经在主线程上调用了那个调用,所以崩溃没有意义:一个不同的线程拥有它。”在View属性上。经过进一步调查,我找到了原因:我是通过方法组调用的。我曾认为使用方法组或委托(delegate)/lambda本质上是同一件事(另请参见thisquestion和thisquestion)。相反,将方法组转换为委托(delegate)会导致代码执行,检查View的值。这是立即完成的,即在导致崩溃的原始(非UI)线程上。如果我改为使用lambda,则稍后会检查属性,因此会在正确的线

c# - CS1501 : No overload for method 'ToString' takes 0 arguments?

ToString的无重载怎么可能采用零参数?零参数ToString是System.Object的一部分!编辑以回应接近投票:由于我无法将我的构建服务器升级到.NET4.5,有什么方法可以使此代码与.NET4.0/VS2010编译器?没有给我的重载一个完全不同的名称,这并不酷。所讨论的对象是一个F#区分联合,它覆盖了从System.Object继承的ToString方法。被覆盖的ToString正在被属于同一解决方案的C#项目中的代码调用。这一切都很好,直到我将ToString的额外重载添加到我的可区分联合中,它接受一个参数。这一切都在我的本地机器上完美构建和运行(VS2012,所有项目

c# - "public new virtual void Method()"是什么意思?

什么时候使用新的虚关键字修饰方法?什么是感情?比如定义一个接口(interface),然后添加一个类来继承这个接口(interface)。而是使用新的virtual来实现接口(interface)方法。interfaceIPrinter{voidPrint();}publicclassPrinterOne:IPrinter{publicvoidPrint(){Console.WriteLine("PrinterOne.");}}publicclassPrinterTwo:PrinterOne{publicnewvirtualvoidPrint(){Console.WriteLine("

c# - 分页列表错误 : The method 'OrderBy' must be called before the method 'Skip'

完整的错误信息如下:“Skip”方法仅支持LINQtoEntities中的排序输入。方法'OrderBy'必须在方法'Skip'之前调用在“PurchaseOrderController”中,我已将这段代码添加到索引方法中://GET:PurchaseOrderpublicActionResultIndex(int?page){returnView(db.PurchaseOrders.ToPagedList(page??1,3));}还在“PurchaseOrders”的索引View中,我添加了这段代码:@usingPagedList;@usingPagedList.Mvc;@mode

c# - 委托(delegate) : Method name expected error

我正在尝试让以下简单的委托(delegate)示例正常工作。根据我从中获取的一本书应该没问题,但我得到了一个Methodnameexpected错误。namespaceTestConsoleApp{classProgram{privatedelegatestringD();staticvoidMain(string[]args){intx=1;Dcode=newD(x.ToString());}}}有什么帮助吗? 最佳答案 删除():Dcode=newD(x.ToString);您想指定方法,而不是执行。

c# - .NET 4.5 中的代码契约 + 异步 : "The method or operation is not implemented"

在Windows7x64上的VS2012中使用CodeContracts1.4.51019.0时,我从ccrewrite收到以下编译错误:“方法或操作未实现."这似乎是由属性访问器的组合和使用缺少内部await的async方法引起的。复制步骤:创建一个启用“完整”运行时契约检查的新类库:namespaceCodeContractsAsyncBug{usingSystem.Threading.Tasks;publicclassService{//Offendingmethod!publicasyncTaskProcessAsync(Entityentity){varflag=entity