草庐IT

non_empty

全部标签

c# - .NET/BCL 源中 "string.Empty"以上混淆注释的含义?

我试图理解为什么string.Empty是readonly而不是const。我看到了this发布,但我不明白微软对此发表的评论。作为乔恩双向飞碟wrote在评论中“我不知道-老实说,这对我来说没有多大意义......”SharedSourceCommonLanguageInfrastructure2.0Release.string.cs在sscli20\clr\src\bcl\system\string.cs中//TheEmptyconstantholdstheemptystringvalue.//WeneedtocalltheStringconstructorsothatthecom

c# - yield break 是否等同于从返回 IEnumerable<T> 的方法返回 Enumerable<T>.Empty

这两种方法对我来说似乎是一样的publicIEnumerableGetNothing(){returnEnumerable.Empty();}publicIEnumerableGetLessThanNothing(){yieldbreak;}我在测试场景中分析了每一个,我没有发现速度上有什么明显的差异,但是yieldbreak版本稍微快一些。是否有理由使用一个而不是另一个?一个比另一个更容易阅读吗?是否存在对调用者重要的行为差异? 最佳答案 如果你打算总是返回一个空的枚举然后使用Enumerable.Empty()语法更具声明性恕我

C# 错误 : "An object reference is required for the non-static field, method, or property"

我有两个类,一个用于定义算法参数,另一个用于实现算法:1类(算法参数):usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceVM_Placement{publicstaticclassAlgorithmParameters{publicstaticintpop_size=100;publicstaticdoublecrossover_rate=0.7;publicstaticdoublemutation_rate=0.001;publicstaticintchrom

c# - MVC : The parameters dictionary contains a null entry for parameter 'k' of non-nullable type 'System.Int32'

我是MVC的新手。在我的应用程序中,我正在从Mydatabase中检索数据。但是当我运行我的应用程序时,它会显示这样的错误这是我的网址http://localhost:7317/Employee/DetailsData/4ExceptionDetails:System.ArgumentException:Theparametersdictionarycontainsanullentryforparameter'k'ofnon-nullabletype'System.Int32'formethod'System.Web.Mvc.ActionResultDetailsData(Int32)

docker - "Empty continuation lines will become errors"...我现在应该如何评论我的Dockerfile?

考虑以下Dockerfile:FROMalpine:edgeEXPOSE\#webportal8080\#backdoor8081这样构建:dockerbuild.我们观察到这样的输出:SendingbuildcontexttoDockerdaemon17.1TBStep1/2:FROMalpine:edge--->7463224280b0Step2/2:EXPOSE80808081--->Usingcache--->7953f8df04d9[WARNING]:Emptycontinuationlinefoundin:EXPOSE80808081[WARNING]:Emptyconti

docker - "Empty continuation lines will become errors"...我现在应该如何评论我的Dockerfile?

考虑以下Dockerfile:FROMalpine:edgeEXPOSE\#webportal8080\#backdoor8081这样构建:dockerbuild.我们观察到这样的输出:SendingbuildcontexttoDockerdaemon17.1TBStep1/2:FROMalpine:edge--->7463224280b0Step2/2:EXPOSE80808081--->Usingcache--->7953f8df04d9[WARNING]:Emptycontinuationlinefoundin:EXPOSE80808081[WARNING]:Emptyconti

c# - If string is not null or empty else 的一行

出于各种原因,我通常在整个应用程序中使用这样的东西:if(String.IsNullOrEmpty(strFoo)){FooTextBox.Text="0";}else{FooTextBox.Text=strFoo;}如果我要经常使用它,我将创建一个返回所需字符串的方法。例如:publicstringNonBlankValueOf(stringstrTestString){if(String.IsNullOrEmpty(strTestString))return"0";elsereturnstrTestString;}并像这样使用它:FooTextBox.Text=NonBlankVa

c# - 为什么使用 EventArgs.Empty 而不是 null?

我记得在多个场合和多个地点读到,在触发典型事件时:protectedvirtualOnSomethingHappened(){this.SomethingHappened(this,EventArgs.Empty);}如果没有有趣的事件参数,e应该是EventArgs.Empty,而不是null。我遵循了我的代码中的指导,但我意识到我不清楚为什么这是首选技术。为什么规定的契约(Contract)更喜欢EventArgs.Empty而不是null? 最佳答案 我相信NOTNULL背后的原因是当作为参数传递时,该方法不需要潜在地处理空引

c# - 不能使用 String.Empty 作为可选参数的默认值

我正在阅读BillWagner的EffectiveC#。在项目14-最小化重复初始化逻辑中,他展示了以下在构造函数中使用新的可选参数功能的示例:publicMyClass(intinitialCount=0,stringname="")注意他用了""而不是string.Empty。他评论道:You'llnote[inanexampleabove]thatthesecondconstructorspecified""forthedefaultvalueonthenameparameter,ratherthanthemorecustomarystring.Empty.That'sbecau

c# - Enumerable.Empty<T>() 等效于 IQueryable

当方法返回IEnumerable时我没有任何东西可以返回,我们可以使用Enumerable.Empty().对于返回IQueryable的方法,是否有与上述等效的方法? 最佳答案 也许:Enumerable.Empty().AsQueryable(); 关于c#-Enumerable.Empty()等效于IQueryable,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/2691