草庐IT

instance-methods

全部标签

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# - ExecuteScalar 调用抛出异常 "Object reference not set to an instance of an object"

在单元测试中调试以下方法时出现以下错误Objectreferencenotsettoaninstanceofanobject点击以下行时result=(int)validateDatabase.ExecuteScalar();方法是publicstaticBooleanValidate(stringargument1,stringargument2){intresult=-1;using(varconnection=newSqlConnection("connectionstring")){SqlCommandvalidateDatabase=newSqlCommand("PROCED

c# - ASP.NET MVC : How to obtain assembly information from HtmlHelper instance?

我在一个独立于我的MVC应用程序程序集的程序集中有一个HtmlHelper扩展方法。在扩展方法中,我想获取MVC应用程序程序集的版本号。这可能吗?调用程序集是razorView动态程序集,因此没有帮助。HtmlHelper中是否嵌套了某个对象可以为我提供MVC应用程序程序集的版本号?我一直在探索HtmlHelperclassdocumentation但到目前为止还没有找到解决我的问题的方法。谢谢! 最佳答案 这是出了名的邪恶-因为不幸的是,没有一种特定的可靠方法可以做到这一点。但是,由于它是一个MVC应用程序,它很可能有一个Glob

c# - GetProperty BindingFlags.IgnoreCase 在 c# 中没有 public 和 Instance 将无法工作

Typet=typeof(T);t.GetProperty("Company")如果我写下面的代码,它会返回nullTypet=typeof(T);t.GetProperty("company",BindingFlags.IgnoreCase)与此同时,如果我写这个工作正常。为什么会这样?Typet=typeof(T);t.GetProperty("company",BindingFlags.IgnoreCase|BindingFlags.Public|BindingFlags.Instance) 最佳答案 不采用BindingFl

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# - cocos2d-xna : sprite is not drawn if using instance of a class inherited from sprite

我有一个基于Cocos2DXNA和MonoGame的游戏项目。我想在CCSprite类中添加一些自定义逻辑,所以我创建了一个继承自CCSprite的类。我添加了一个虚拟自动属性并尝试使用此类,但出于某种原因,作为我的自定义Sprite类实例创建的Sprite未显示在图层上,而作为CCSprite类实例的Sprite完全没问题。代码如下所示:publicclassSprite:CCSprite{publicstringSomeProp{get;set;}}...line1:varmySprite1=newSprite("texture.png");line2:varmySprite1=n

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

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

c# - SOAP 错误 : "Server was unable to process request" "Object reference not set to an instance of an object"

当我向本地IIS中的服务发送SOAP请求时,一切正常。当我向在另一台主机上的IIS上运行的同一服务发送SOAP请求时,一切正常。但是当另一个程序员向我的服务发送SOAP请求时,他通常会得到正确的响应,除了返回服务中的一个方法:soap:ServerServerwasunabletoprocessrequest.--->Objectreferencenotsettoaninstanceofanobject.我需要了解他收到此错误的原因。他的SOAP请求与SOAP请求完全相同,但我的有效,而他的无效。 最佳答案 如果您不确切知道错