草庐IT

TYPE_NULL

全部标签

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

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

c# - "The type or namespace name ' 使用 ' could not be found"路由 "attribute routing"

只是试图将一些代码从一个工作项目拼接到另一个。“from”项目使用“属性路由”,您可以在WebAPIController模块中嵌入[Route(…)]指令来指示应该将哪个HTTP消息路由到哪个服务例程。在“from”项目中工作正常,但在“to”项目中我收到构建错误“找不到类型或namespace名称‘Route’(是否缺少using指令或程序集引用?)"我已经尝试将“from”项目中的所有using语句基本上复制到“to”项目中,但这没有明显效果。没有任何MS文档表明需要NuGet包(甚至是using语句)。这两个项目都应该是ASP.NETMVC4。(是的,我用config.MapHt

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

c# - 私有(private)成员在 API 方法调用中突然为 null

发生了奇怪的事情:在我的网络api中,我在使用Ninject解析时将一个存储库注入(inject)到Controller中。存储库存储在私有(private)只读成员变量中。工作得很好!当一个api方法被调用时,我访问了这个变量-只是发现它突然变成了null!伪例子:publicclassMyController:ApiController{privatereadonlyIRepo_repo;publicMyController(IReporepo){Guard.AgainstNullArgument("repo",repo);//guardingto//makesureit'snot

c# - ThreadContextChanged 上的 AsyncLocal 值更新为 null

我正在尝试了解AsyncLocal在.Net4.6中的工作方式。我正在将一些数据放入AsyncLocal...但是当ThreadContext更改时它被设置为null。我使用AsyncLocal的全部原因是在等待异步操作时尝试跨线程保留/缓存此值。知道为什么会在上下文更改时专门调用它并将其设置为null吗?关于AsyncLocal的文档非常稀少……也许我完全弄错了。publicclassRequestContextProvider:IRequestContextProvider{privatestaticreadonlyAsyncLocal_requestContext=newAsyn

c# - 比 Dictionary<Type, X> 更快的选择?

我正在创建一个正在进行性能测试的库。在其中我生成了一个Dictionary一次。这些项目当前以随机顺序插入。字典在应用程序生命周期内保持不变。然后它经常用于查找项目。查找是库中较大的瓶颈之一。是的,我正在微观优化,但要学习。我想知道是否有更好的方法来获得查找性能?更新我使用dotTrace来衡量性能。报告+dotTrace在我的家用电脑中,所以我这里没有报告(本可以上传到其他地方)。我使用了这里的测试:https://github.com/danielpalme/IocPerformance字典定义可在此处找到:https://github.com/jgauffin/Griffin.C

c# - 如何找到asp :Login LoginError error type

当asp:Login控件的LoginError事件触发时,我如何找到错误发生的原因?是否有类似e.ErrorType的属性告诉我登录失败的原因?或者我是否必须像本教程中那样手动检查所有内容:http://www.asp.net/security/tutorials/validating-user-credentials-against-the-membership-user-store-cs或http://www.aspnettutorials.com/tutorials/controls/howto-errors-login-asp4-csharp.aspx

c# - 使用泛型类型参数代替 System.Type 类型的参数。是气味吗?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭3年前。Improvethisquestion我经常看到(例如在许多模拟库中)使用泛型类型参数代替System.Type类型参数的方法。我特别讨论的是泛型类型仅在typeof(T)操作中使用的情况(即,方法中的任何地方都没有使用类型T的实例,并且T没有被用于返回值类型或其他参数)。例如考虑以下方法:publicstringGetTypeName(System.Typetype){returntype.FullName;}这个方法通常伴

c# - ConfigurationManager.GetSection 返回 null

这是我的app.config但是当我在代码中调用它时,我得到一个空值publicvoidsamplemethod(){NameValueCollectionnvc=ConfigurationManager.GetSection("procedureList")asNameValueCollection;string[]keys=nvc.AllKeys;}如能指出我做错的地方,我将不胜感激 最佳答案 Usingsectionhandlerstogroupsettingsintheconfigurationfile例如,您可以按照以下内

c# - 尝试打开 telerik 报告时出现 "Value cannot be null. Parameter name: instance"错误

在我的解决方案中,我有telerik报告,当尝试在VisualStudio2010设计器中打开它们时,我收到此错误:Valuecannotbenull.Parametername:instanceCallStackatSystem.ComponentModel.TypeDescriptor.AddAttributes(Objectinstance,Attribute[]attributes)atMicrosoft.VisualStudio.Design.VSDesignSurface.CreateDesigner(IComponentcomponent,BooleanrootDesig