草庐IT

LOAD_DEFAULT

全部标签

c# - 当 new-able 使用 new T(),否则使用 default(T)

我正在研究C#泛型函数。错误时,如果泛型类型可以是new-able,返回newT(),否则返回default(T)。代码如下:privateTFunc(){try{//trytodosomething...}catch(Exceptionexception){if(Tisnew-able)//我知道对于那些使用newT()的人来说,它需要whereT:new()。这个问题是,如何在运行时判断这个? 最佳答案 您只需要检查该类型是否具有无参数构造函数。您可以通过以空类型作为参数调用Type.GetConstructor方法来实现。va

c# - 编译器错误 "Default parameter specifiers are not permitted"

下面是我的代码。publicclassPItem{publicStringcontent;publicintcount;publicintfee;publicintamount;publicstringdescription;//DefaultvaluespublicPItem(String_content="",int_count=0,int_fee=0,string_description="",int_amount=0){content=_content;count=_count这是在一个类里面。当我尝试运行程序时出现此错误:Defaultparameterspecifiersa

c# - 错误 : Could not load file or assembly 'Microsoft. Practices.ServiceLocation,版本 = 1.0.0.0

我收到这个错误:Couldnotloadfileorassembly'Microsoft.Practices.ServiceLocation,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35'oroneofitsdependencies.Thelocatedassembly'smanifestdefinitiondoesnotmatchtheassemblyreference.(ExceptionfromHRESULT:0x80131040)如果我的项目中已有另一个现有版本的Microsoft.Practic

c# - "Could not load file or assembly ' System.Core, Version=2.0.5.0,...”动态加载可移植类库时出现异常

首先,我需要强调的是,这个问题与thisthread中的问题略有不同。.此外,安装KB2468871没有帮助。我尽量简化了这个问题。一般来说,它是关于使用Assembly.LoadFile(...)在桌面应用程序中加载PCL程序集。假设有一个.NET4.0控制台应用程序(称为“C”)。它引用.NET4.0程序集(称为“N4”)和PCL程序集(称为“PCL”)。N4看起来像这样:usingSystem.Linq;namespaceN4{publicclassClassInN4{publicstaticstringGreet(){returnnewstring("hellofromN4".

c# - 如何将 "default(SomeType)"从 C# 转换为 CIL?

我目前正在处理一个涉及System.Reflection.Emit的问题代码生成。我试图弄清楚在我将使用default(SomeType)的地方发出什么CIL在C#中。我在VisualStudio11Beta中运行了一些基本实验。JustDecompile向我显示default(bool)的以下CIL输出,default(string),和default(int?:.localsinit([0]boolV_0,[1]stringV_1,[2]valuetype[mscorlib]System.Nullable`1V_2)//boolb=default(bool);ldc.i4.0stl

c# - Application.Run 和 Form.Load 之间发生了什么?

我有一个用VB.NET为Framework4.5编写的WinForms应用程序。我注意到应用程序的启动时间异常长(我写的其他应用程序在启动时几乎立即启动,这个应用程序需要>5秒)多次启动后启动时间不会改变,所以我猜这不是应用程序首次启动期间未缓存CLR代码的情况。我通过记下启动期间的时间做了一些测试:ModulemodMainPublicMyLogAsSystem.Text.StringBuilderPublicSubMain()MyLog=NewSystem.Text.StringBuilderApplication.EnableVisualStyles()Application.S

c# - ASP.NET : Check for click event in page_load

在C#中,如何检查是否在页面加载方法中单击了链接按钮?我需要知道在触发点击事件之前它是否被点击。 最佳答案 if(IsPostBack){//getthetargetofthepost-back,willbethenameofthecontrol//thatissuedthepost-backstringeTarget=Request.Params["__EVENTTARGET"].ToString();} 关于c#-ASP.NET:Checkforclickeventinpage_lo

c# - 错误 : Could not load log4net assembly

我正在寻找解决这个错误的办法:Couldnotloadfileorassembly'log4net,Version=1.2.10.0,Culture=neutral,PublicKeyToken=692fbea5521e1304'oroneofitsdependencies.Thesystemcannotfindthefilespecified."Thiserrorislocatedintheweb.configfile.当我将log4net.dll复制到我的webapp的bin目录时,我得到一个Couldnotloadfileorassembly'log4net,Version=1.

c# - 泛型类型值和 '==' 关键字的 'default' 运算符的行为是什么?

问题的第1部分:在下面的代码中,为什么value==default可以正常编译,而其他替代方案却不能?boolMyEqual(Tvalue){Tvalue2=default;if(value==value2)//Error:Operator'=='cannotbeappliedtooperandsoftype'T'and'T'returntrue;if(value==default(T))//Error:Operator'=='cannotbeappliedtooperandsoftype'T'and'T'returntrue;if(value==default)//Noerrorre

c# - MemoryCache.Default 在 .NET Core 中不可用?

我正在将一些代码从.NET4.6移植到.NETCore,但在使用MemoryCache时遇到了一些问题。4.6代码使用MemoryCache.Default来实例化缓存,但这在.NETCore中似乎不可用。在.NETCore中是否有与此等效的东西,或者我应该将自己的MemoryCache更新为单例并通过IOC注入(inject)它? 最佳答案 System.Runtime.Caching.MemoryCache和Microsoft.Extensions.Caching.Memory.MemoryCache是完全不同的实现。它们很相似