草庐IT

null_object

全部标签

c# - 为什么我不能将 List<Customer> 作为参数传递给接受 List<object> 的方法?

下面的代码给我这个错误:Cannotconvertfrom'System.Collections.Generic.List'to'System.Collections.Generic.List'.我如何向编译器表明Customer确实继承自对象?或者它只是不对通用集合对象进行继承(发送List会得到相同的错误)。usingSystem.Collections.Generic;usingSystem.Windows;usingSystem.Windows.Documents;namespaceTestControl3423{publicpartialclassWindow2:Window

c# - object @object 是什么意思

我一直在玩弄事件和委托(delegate),需要异步引发我的事件,因此我一直在使用:publiceventEventHandlerOnHelloEvent;publicvoidRaise(){IAsyncResultsyncResult=OnHelloEvent.BeginInvoke(this,newEventArgs(),null,null)在Intellisense中,最后一个null被声明为object@object。我以前没有遇到过这个问题,而且似乎找不到任何相关文档。这是什么意思?有用吗? 最佳答案 @符号可以被认为是某

c# - 将 Object[] 转换为 String[] 或 List<String> 的最佳方法

我有一个数据行。我可以使用属性dataRow.ItemArray获取其中的项目这是类型object[].我需要将其转换为String[]或List我看到了方法ToArray和ToList.但不知道如何使用它。请帮忙。提前致谢 最佳答案 根据dataRow.ItemArray中的实际对象,您有两种选择如果object[]中确实有字符串对象,您可以只对元素进行明智的转换。dataRow.ItemArray.OfType().ToList();但如果对象是另一种类型,如int或其他类型,您需要将其转换为字符串(在本例中为.ToString

c# - 比较可为 null 的日期时间对象

我有两个可为null的日期时间对象,我想比较两者。最好的方法是什么?我已经试过了:DateTime.Compare(birthDate,hireDate);这给出了一个错误,也许它期望类型为System.DateTime的日期并且我有Nullabledatetimes。我也试过:birthDate>hiredate...但结果并不如预期...有什么建议吗? 最佳答案 比较两个Nullable对象使用Nullable.Compare喜欢:boolresult=Nullable.Compare(birthDate,hireDate)>0

c# - WCF 服务协定是否可以具有可为 null 的输入参数?

我有一个这样定义的契约(Contract):[OperationContract][WebGet(UriTemplate="/GetX?myStr={myStr}&myX={myX}",BodyStyle=WebMessageBodyStyle.Wrapped)]stringGetX(stringmyStr,int?myX);我得到一个异常(exception):[InvalidOperationException:契约(Contract)“IMyGet”中的操作“GetX”有一个名为“myX”的查询变量,类型为“System.Nullable1[System.Int32]”,但类型为

c# - 为什么 object.ToString() 存在?

IStringable接口(interface)不是更优雅、更整洁吗?谁需要返回给我们的这个Type.FullName对象?编辑:每个人都在问为什么我认为它更优雅..好吧,就像那样,对象将具有CompareTo方法,而不是IComparable,默认情况下会抛出异常或返回0。有些对象不能也不应该描述为字符串。对象同样可以返回string.Empty。Type.FullName只是一个任意选择..而对于Console.Write(object)等方法,我认为应该是:Write(IStringable)。但是,如果您将WriteLine用于除字符串以外的任何内容(或者它的ToString很

c# - 如果字符串为 null 或空,为什么 string.Split (";") 不会抛出错误?

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。如果字符串为空或null,string.split(";")不应该抛出错误吗?对我来说,我正在尝试这段代码并且没有任何错误,stringa=string.empty;if(a.Split(';').Length-1谁能告诉我为什么它不抛出错误以及为什么if语句为真。

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

C# 帮助 : Sorting a List of Objects in C#

这个问题在这里已经有了答案:关闭13年前。PossibleDuplicates:SortobjectsusingpredefinedlistofsortedvaluesC#Help:SortingaListofObjectsinC#DoublePostSortingaListofobjectsinC#publicclassCarSpecs{publicCarSpecs(){}privateString_CarName;publicStringCarName{get{return_CarName;}set{_CarName=value;}}privateString_CarMaker;p

c# - "Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context"

我不知道这个错误是什么意思。我使用的是VisualStudioforMac7.5.0社区版。我在带有ASP.NETCore的EntityFramework中使用延迟加载。publicpartialclassAdminUser{publicAdminUser(){RoleAssign=newHashSet();}publicGuidUserId{get;set;}publicstringFirstName{get;set;}publicstringLastName{get;set;}publicstringEmail{get;set;}publicstringUserName{get;s