草庐IT

non-nullable

全部标签

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)

c# - 在 C#/.NET 中将参数标记为 NOT nullable?

是否有一个简单的属性或数据协定,我可以将其分配给防止null的函数参数?从在C#/.NET中传递?理想情况下,这还将在编译时进行检查以确保文字null没有在任何地方使用它并且在运行时抛出ArgumentNullException.目前我写的是...if(null==arg)thrownewArgumentNullException("arg");...对于我认为不是null的每个参数.同理,有没有Nullable的反义词?因此以下将失败:NonNullables=null;//throwsomekindofexception 最佳答案

c# - 如何将 DateTime.TryParse 与 Nullable<DateTime> 一起使用?

我想使用DateTime.TryParse方法将字符串的日期时间值放入Nullable。但是当我尝试这个时:DateTime?d;boolsuccess=DateTime.TryParse("somedatetext",out(DateTime)d);编译器告诉我'out'argumentisnotclassifiedasavariable不确定我需要在这里做什么。我也试过:out(DateTime)d.Value这也行不通。有什么想法吗? 最佳答案 正如Jason所说,您可以创建一个正确类型的变量并传递它。您可能希望将其封装在您自

c# - 为什么我会收到消息 "Invalid setup on a non-virtual (overridable in VB) member..."的异常?

我有一个单元测试,我必须模拟一个返回bool类型的非虚拟方法publicclassXmlCupboardAccess{publicboolIsDataEntityInXmlCupboard(stringdataId,outstringnameInCupboard,outstringrefTypeInCupboard,stringnameTemplate=null){returnIsDataEntityInXmlCupboard(_theDb,dataId,outnameInCupboard,outrefTypeInCupboard,nameTemplate);}}所以我有一个XmlCu

c# - 类型 'string' 必须是不可为 null 的类型才能将其用作泛型类型或方法 'System.Nullable<T>' 中的参数 T

为什么我会收到错误消息“类型‘字符串’必须是不可空值类型才能将其用作泛型类型或方法‘System.Nullable’中的参数‘T’”?usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Diagnostics;usingUniverse;namespaceUniverse{publicclassclsdictionary{privatestring?m_Word="";privatestring?m_Meaning="";string?Word{

c# - Nullable<T>.HasValue 或 Nullable<T> != null 之间有什么区别?

我一直使用Nullable.HasValue因为我喜欢语义。然而,最近我正在研究其他人现有的代码库,他们在其中使用了Nullable!=null。专门代替。是否有理由使用一个而不是另一个,还是纯粹是偏好?int?a;if(a.HasValue)//...对比int?b;if(b!=null)//... 最佳答案 编译器将null比较替换为对HasValue的调用,因此没有真正的区别。只做对您和您的同事来说更具可读性/更有意义的事情。 关于c#-Nullable.HasValue或Null

javascript - 错误 : [$compile:nonassign] Expression 'undefined' used with directive 'myFacebook' is non-assignable

我正在用angularjs编写一个指令并得到上面提到的错误。我正在使用一本书中的代码。.directive('myFacebook',[function(){return{link:function(scope,element,attributes){(function(d){varjs,id='facebook-jssdk',ref=d.getElementsByTagName('script')[0];if(d.getElementById(id)){return;}js=d.createElement('script');js.id=id;js.async=true;js.src

转到 1.12 模块 : local import in non-local import

我目前正在使用Go1.12模块并且对导入感到厌烦。我正在使用gin(网络微服务)和gorm(golangorm)制作rest-api。在golang模块中工作时一切仍然正常。但是在导入本地包时遇到问题目录树:go.mod:modulegithub.com/Aragami1408/go-gormgo1.12require(github.com/gin-gonic/ginv1.4.0github.com/jinzhu/gormv1.9.9github.com/lib/pqv1.1.1github.com/satori/go.uuidv1.2.0)db.go:packagedb//codeb

golang - 将枚举类型保存到 SQL 数据库 "panic: sql: converting Exec argument #1' s 类型 : non-Value type int returned from Value"

在我当前的go项目(~5KLOC)中,我使用sqlite3作为我的底层数据库层,我使用gorm作为我的ORM引擎。其中一个模型是一个Platform,其字段为PlatformType枚举类型。这是演示我的问题的代码片段。packagemainimport(_"github.com/jinzhu/gorm/dialects/sqlite""github.com/jinzhu/gorm""database/sql/driver""fmt")/****************************\ObjectLayer\****************************///Pla