草庐IT

null_type

全部标签

c# - 在 C# 中使用 Type.GetType() 返回的类型

我有一个关于如何可能的问题(如果可能的话:)例如,使用Type.GetType()返回的类型引用来创建该类型的IList?这里是示例代码:Typecustomer=Type.GetType("myapp.Customer");IListcustomerList=newList();//gotanerrorhere=[提前致谢! 最佳答案 像这样:TypelistType=typeof(List).MakeGenericType(customer);IListcustomerList=(IList)Activator.CreateIn

c# - 将 nullable double 设置为 null 有什么问题?

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicates:Whycan'tIsetanullableinttonullinaternaryifstatement?Nullabletypesandtheternaryoperator.Whywon'tthiswork?下面有什么问题publicdouble?Progress{get;set;}Progress=null;//worksProgress=1;//worksProgress=(1==2)?0.0:null;//failsTypeofconditionalexpressioncannotbedetermin

c# - 使用 MultipartFormDataContent 生成错误的 Content-Type header

我有以下代码:privatestaticstringboundary="----CustomBoundary"+DateTime.Now.Ticks.ToString("x");privatestaticasyncTaskPostTest(){stringservResp="";using(varcontent=newMultipartFormDataContent(boundary)){content.Add(newStringContent("105212"),"case-id");content.Add(newStringContent("1/14/2014"),"dateFro

c# - 我怎么能在int上执行方法?在没有 NullReferenceException 的情况下设置为 null?

我在MSDN上读到:Thenullkeywordisaliteralthatrepresentsanullreference,onethatdoesnotrefertoanyobject.但是我看到下面的代码运行时没有抛出任何异常:int?i=null;vars=i.ToString();那么如果变量i为null,为什么我可以执行它的方法呢? 最佳答案 因为int?实际上是一个Nullable和Nullable是struct,和一个结构cannotbenull.就是这样Nullabletypeswork.它们不是引用值,所以它们不能

c# - 序列化异常 : Type is not resolved for member "..."

我一直在尝试将程序集动态加载到AppDomain。我需要这样做是因为我想动态调用一个方法,但在我的应用程序运行时不要保留DLL的句柄,以便在需要时可以替换它。但我收到此SerializationException异常:类型未解析成员“...”这是我的代码:AppDomaindomain=AppDomain.CreateDomain("TempAppDomain",null,AppDomain.CurrentDomain.SetupInformation);try{objectobj=domain.CreateInstanceFromAndUnwrap(dllPath,typeName)

c# 代码似乎以一种无效的方式进行了优化,使得对象值变为 null

我的以下代码出现了一个奇怪的问题:varall=newFeatureService().FindAll();System.Diagnostics.Debug.Assert(all!=null,"FindAllmustnotreturnnull");System.Diagnostics.Debug.WriteLine(all.ToString());//throwsNullReferenceExceptionFindAll方法的签名是:publicListFindAll()通过代码我已经确认FindAll的返回值不为空,正如您从断言中看到的那样,“all”变量不为空,但在下一行中它似乎为

c# - 空文本框是否被视为空字符串或 null?

有问题的文本框包含在我的代码中的if语句中,其效果为if(textbox.text!=""){dothis}我很好奇空文本框是否会被视为空字符串或空语句。 最佳答案 尝试使用IsNullOrWhiteSpace,这将确保验证空白,而无需修剪它。if(!string.IsNullOrWhiteSpace(textbox.Text)){//codehere}根据文档string.IsNullOrWhiteSpace计算为:returnString.IsNullOrEmpty(value)||value.Trim().Length==0;

c# - ExternalLoginInfo 电子邮件在 Microsoft 和 Facebook oauth2、MVC C# 中始终为 null?

我正在为ExternalLoginCallback使用以下代码在google中一切正常。但在Facebook和Microsoft中,loginInfo.Email始终为空。以下代码有什么问题?[AllowAnonymous]publicasyncTaskExternalLoginCallback(stringreturnUrl){ExternalLoginInfologinInfo=awaitAuthenticationManager.GetExternalLoginInfoAsync();if(loginInfo==null){returnRedirectToAction("Logi

c# - 将 List<object> 转换为 List<Type>,类型在运行时已知

我正在实现某种反序列化并遇到下一个问题:我有List和System.Reflection.Field,它是FieldType可以是List,List或List,所以我需要从List转换到那种类型。publicstaticobjectConvertList(Listvalue,Typetype){//typemaybeList,List,List}我可以单独写每个案例,但应该有更好的方法使用反射。 最佳答案 我相信你想要的是:publicstaticobjectConvertList(Listvalue,Typetype){varco

c# - NaoQi 和 Leap 问题 : An unhandled exception of type 'System.BadImageFormatException' . .. 并且无法加载文件或程序集

目前,我遇到了一个问题,我无法通过Google上的解决方案解决这个问题。到目前为止没有任何效果。当我编译LeapMotion代码并导入NaoqiC#库时,它工作正常。当我实际尝试使用一行代码连接到机器人时,我的程序崩溃了。我的程序设置为为任何CPU构建。.dll被Leap库和NaoQi库引用,并且.dll被放置在调试文件夹和项目文件夹中以备不时之需。目前我还不知道问题出在哪里。这里有人能弄清楚吗?我会很高兴让这个工作。这是第一条错误信息,然后它要求我中断或继续:Anunhandledexceptionoftype'System.BadImageFormatException'occur