草庐IT

method_descriptor

全部标签

C# 编译器 : cannot access static method in a non-static context

我有下面的代码:publicclassAnything{publicintData{get;set;}}publicclassMyGenericBase{publicvoidInstanceMethod(Tdata){//dosomejob}publicstaticvoidStaticMethod(Tdata){//dosomejob}//othersmembers...}publicsealedclassUsefulController:MyGenericBase{publicvoidProxyToStaticMethod(){StaticMethod(null);}//others

c# - "Property set method not found"反射时出错

我正在尝试反射(reflect)一些类属性并以编程方式设置它们,但看起来我的PropertyInfo过滤器之一不起作用://Getallpublicorprivatenon-staticpropertiesdeclaredinthisclass(noinheritedproperties)-thathaveagetterandsetter.PropertyInfo[]props=this.GetType().GetProperties(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public|BindingF

c# - 错误 : "an object reference is required for the non-static field, method or property..."

这个问题在这里已经有了答案:CS0120:Anobjectreferenceisrequiredforthenonstaticfield,method,orproperty'foo'(9个回答)关闭5年前。我正在用C#创建一个应用程序。它的功能是评估给定的是否为素数以及相同的交换数是否也是素数。当我在VisualStudio中构建我的解决方案时,它说“非静态字段、方法或属性需要对象引用...”。我在使用“volteado”和“siprimo”方法时遇到了这个问题。问题出在哪里,我该如何解决?namespaceConsoleApplication1{classProgram{static

c# - 是什么导致这里出现 "extension methods cannot be dynamically dispatched"?

编译错误'System.Data.SqlClient.SqlConnection'hasnoapplicablemethodnamed'Query'butappearstohaveanextensionmethodbythatname.Extensionmethodscannotbedynamicallydispatched.Considercastingthedynamicargumentsorcallingtheextensionmethodwithouttheextensionmethodsyntax.现在,我知道如何解决该问题,但我正试图更好地了解错误本身。我有正在构建的类来利

c# - Equals Method 的默认行为是什么?

设A是一个类,其中一些成员为x、y、z:ClassA{intx;inty;Stringz;...}A是一个对象,因此它继承了对象中定义的“等于”函数。这个函数的默认行为是什么?它是检查成员的相等性还是检查引用的相等性? 最佳答案 ThedefaultimplementationofEqualssupportsreferenceequalityforreferencetypes,andbitwiseequalityforvaluetypes.Referenceequalitymeanstheobjectreferencesthatar

C# 错误 : "An object reference is required for the non-static field, method, or property"

我有两个类,一个用于定义算法参数,另一个用于实现算法:1类(算法参数):usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceVM_Placement{publicstaticclassAlgorithmParameters{publicstaticintpop_size=100;publicstaticdoublecrossover_rate=0.7;publicstaticdoublemutation_rate=0.001;publicstaticintchrom

c# - 错误 : "Cannot use ' async' on methods without bodies". 如何强制异步子覆盖?

我在一个系统上工作,在这个系统中,多个客户端对象需要通过一个接口(interface)实现一个特定的功能,我希望该功能与延续异步运行(我希望实现是I/O绑定(bind)的并希望确保所有客户端对象尽快完成此功能)。我正在使用VisualStudioAsyncCTPRefreshforSP1,使用C#“5.0”。在我的抽象类的子对象中强制执行异步行为的推荐做法是什么(见下文)?我不能(显然)使用虚拟方法方法强制使用“异步”方法。我只能要求“任务”返回类型。这是否意味着我根本不应该尝试在子对象中要求异步行为?在那种情况下,返回类型应该只是“void”吗?公共(public)接口(interf

时间:: console application - static methods

为什么在C#中,控制台应用程序,在默认的“程序”类中,所有方法都必须是静态的staticvoidMain(string[]args) 最佳答案 成员函数不必是静态的;但如果它们不是静态的,则需要您实例化一个Program对象才能调用成员方法。使用静态方法:publicclassProgram{publicstaticvoidMain(){System.Console.WriteLine(Program.Foo());}publicstaticstringFoo(){return"Foo";}}没有静态方法(换句话说,要求您实例化Pr

c# - += new EventHandler(Method) 与 += 方法

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:C#:Differencebetween‘+=anEvent’and‘+=newEventHandler(anEvent)’订阅事件有两种基本方式:SomeEvent+=newEventHandler(MyHandlerMethod);SomeEvent+=MyHandlerMethod;有什么区别,什么时候我应该选择一个而不是另一个?编辑:如果是一样的,那么为什么VS默认为长版本,使代码困惑?这对我来说毫无意义。

c# - .NET 中 "HttpRequest.RequestType"和 "WebRequest.Method"值的常量在哪里?

我需要在ASP.NET(或WebRequest.Method)中检查HttpRequest的RequestType。我知道我可以只使用字符串值“POST”或“GET”作为请求类型,但我可以发誓在某个类的某处有一个常量包含值的.NET。出于好奇,我想知道是否有人知道这些用于GET和POST的字符串常量在哪个类中。我尝试在线搜索但我没有运气好,所以我想我应该在这里问。 最佳答案 System.Net.WebRequestMethods.Http.Connect="CONNECT".Get="GET".Head="HEAD".MkCol=