草庐IT

if-null-then-null

全部标签

c# - int.TryParse = null 如果不是数字?

如果无法将字符串解析为int,是否有返回null的方法?与:public....,string?categoryID){int.TryParse(categoryID,outcategoryID);获取“无法从‘outstring’转换为‘outint’”怎么办?编辑:由于asp.net的限制不再相关是解决问题的方法/M 最佳答案 首先,为什么要尝试将字符串解析为int并将结果粘贴回字符串?方法签名是boolint.TryParse(string,outint)所以你必须给一个int类型的变量作为第二个参数。这也意味着如果解析失败,

c# - 如何使用 Linq 处理带有 FirstOrDefault 的 NULL 对象属性

我真正的应用程序问题如下所示Employeeempl=newEmployee(397947,"David","Redson",80000);employees.Add(empl);employees.Add(newEmployee(174966,"Alfred","Swanson",50000));employees.Add(newEmployee(848024,"Alima","Bieyrou",40000));employees.Add(newEmployee(number:397462,fName:"Robert",lName:"Nants",salary:30000));str

C# if 语句。内部运作 Q

我刚刚在某些Exchange2010代码中看到了这个代码片段,我想知道是否有人知道为什么程序员会这样做。我从未见过这样格式的If语句。看起来如此倒退,一定有充分的理由吧??if(true==MsgItem.HasAttachments){//Code}我假设它可能对同一事物的各种其他编码方式进行了一些优化;if(MsgItem.HasAttachments){//Code}或if(MsgItem.HasAttachments==true){//Code}这没什么大不了的,我只是好奇。谢谢,迈克更新:感谢您提出的所有有趣的观点。总结似乎是因为遗留编码标准。 最

c# - 在 Mono 和 .NET 之间拆分的编译器 #if 指令

这个问题在这里已经有了答案:HowcanIconditionallycompilemyC#forMonovs.Microsoft.NET?(2个答案)关闭9年前。我需要为Mac上的Mono和PC上的.NET双重编译一个类库。我想做一些小改动,但我希望使用编译器指令拆分代码。有什么建议吗?

c# - 相当于 Promise.then() 的任务是什么?

通过使用Promise(s)为TypeScript添加async/await,在语法上看起来非常接近Task(s)。例子:promise(TS)publicasyncmyAsyncFun():Promise{letvalue:T=await...returnvalue;}任务(C#)publicasyncTaskMyAsyncFun(){Tvalue=await...returnvalue;}我想知道是否反过来,对于Task(s)是否存在等同于.then()的方法。例子:promise(TS)Promisepromise=...promise.then((result:T)=>...d

c# - Sum() 在 Entity Framework 查询中返回 null

我有一个包含这些行的大型EntityFramework查询。varprograms=frompinRepository.Query()wherep.OfficeId==CurrentOffice.IdlettotalCharges=p.ProgramBillings.Where(b=>b.Amount>0&&b.DeletedDate==null).Select(b=>b.Amount).Sum()lettotalCredits=p.ProgramBillings.Where(b=>b.Amount-b.Amount).Sum()letbillingBalance=(totalChar

c# - 销毁对象时自定义事件是否需要设置为null?

假设我们有2个对象,Broadcaster和Listener。Broadcaster有一个名为Broadcast的事件,Listener订阅了该事件。如果Listener在没有取消订阅Broadcast事件的情况下被释放,它将保留在内存中,因为Broadcaster包含引用它的事件委托(delegate)。我很好奇的是,如果Broadcaster在没有Listener取消订阅或Broadcaster设置Broadcast=null的情况下被处置,Broadcaster是否会保留在内存中?除了一位博主认为不将事件设置为null会将源保留在内存中(找到here)之外,我无法找到任何对这个问

c# - ASP.net Core 2.0 中的 appsettings.json 预览配置 GetSection null

我试图从Startup.cs中的注入(inject)配置调用GetSection。值为null,而indexer到具体部分值返回non-null值。在我看来,GetSection方法背后有一个错误,或者我错了?appsettings.json:{"MyConfig":{"ConfigA":"valueA","ConfigB":"valueB"}}程序.cs:publicstaticvoidMain(string[]args){varhost=BuildWebHost(args);host.Run();}publicstaticIWebHostBuildWebHost(string[]a

c# - ConfigurationManager 返回 null 而不是字符串值

我正在尝试从存储在我的工作目录中的App.config文件中检索值,但是当我运行该程序时它返回null。我很困惑为什么会这样,并且多次查看代码以试图发现错误。这是我的App.config文件代码:这是我的C#代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Configuration;usingSystem.Data;usingSystem.Data.Common;namespaceDataProviderFun{classProgram{static

c# - T4 模板错误 : loading the include file ef. utility.cs.ttinclude 返回了 null 或空字符串

我已经覆盖了Controller生成T4模板(ControllerWithContext.tt),如here所述.我想利用在POCO模型生成器T4模板中使用的EF.utility.CS.ttinclude中的代码帮助实用程序。因此,我将以下行从我的Model.tt复制到我的ControllerWithContext.tt。但是,当我尝试添加Controller时,我收到了错误消息Loadingtheincludefile'EF.utility.CS.ttinclude'returnedanulloremptystring根据MSDNdocumentation,这个错误是因为包含的文件是