草庐IT

help-system

全部标签

c# - 从 'System.Int32' 到 'System.Nullable` 1[[System.Int32, mscorlib]] 的转换无效

Typet=typeof(int?);//willgetthisdynamicallyobjectval=5;//willgetthisdynamicallyobjectnVal=Convert.ChangeType(val,t);//gettingexceptionhere我在上面的代码中得到了InvalidCastException。对于上面我可以简单地写int?nVal=val,但上面的代码是动态执行的。我得到一个值(不可为null的类型,如int、float等)包裹在一个对象(这里是val)中,我必须通过将它转换为另一种类型(可以或不能)来将它保存到另一个对象是它的可空版本)。

c# - 在哪里可以找到 System.Web.Helpers、System.Web.WebPages 和 System.Web.Razor?

我正在关注这个article在RazorGenerator上,它说我必须添加对以下内容的引用:System.Web.Helpers.dllSystem.Web.WebPages.dllSystem.Web.Razor.dll当我执行AddReference时,我唯一能看到的是System.Web.Razor,但我不知道其他的在哪里。 最佳答案 您将在VisualStudio2010、2012和2013(引用管理器)中的程序集下的扩展组中找到这些程序集 关于c#-在哪里可以找到System

c# - 在哪里可以找到 System.Web.Helpers、System.Web.WebPages 和 System.Web.Razor?

我正在关注这个article在RazorGenerator上,它说我必须添加对以下内容的引用:System.Web.Helpers.dllSystem.Web.WebPages.dllSystem.Web.Razor.dll当我执行AddReference时,我唯一能看到的是System.Web.Razor,但我不知道其他的在哪里。 最佳答案 您将在VisualStudio2010、2012和2013(引用管理器)中的程序集下的扩展组中找到这些程序集 关于c#-在哪里可以找到System

c# - 为什么我不能引用 System.ComponentModel.DataAnnotations?

我正在尝试在我的WPF项目中使用DataAnnotations来指定字符串的最大长度,如下所示:usingSystem.ComponentModel.DataAnnotations;但是,我得到了错误Thetypeornamespacename'DataAnnotations'doesnotexistinthenamespace'System.ComponentModel'(areyoumissinganassemblyreference?)我见过其他示例,其中DataAnnotations确实存在于此命名空间中。我正在使用C#4。我有什么理由不能使用它吗?我该怎么做才能修复它?

c# - 为什么我不能引用 System.ComponentModel.DataAnnotations?

我正在尝试在我的WPF项目中使用DataAnnotations来指定字符串的最大长度,如下所示:usingSystem.ComponentModel.DataAnnotations;但是,我得到了错误Thetypeornamespacename'DataAnnotations'doesnotexistinthenamespace'System.ComponentModel'(areyoumissinganassemblyreference?)我见过其他示例,其中DataAnnotations确实存在于此命名空间中。我正在使用C#4。我有什么理由不能使用它吗?我该怎么做才能修复它?

c# - Linq Query 一直抛出 "Unable to create a constant value of type System.Object....",为什么?

以下是代码示例:privatevoidloadCustomer(intcustIdToQuery){vardbContext=newSampleDB();try{varcustomerContext=fromtindbContext.tblCustomers//keepsthrowing:wheret.CustID.Equals(custIdToQuery)//Unabletocreateaconstantvalueoftype'System.Object'.selectnew//Onlyprimitivetypes('suchasInt32,String,andGuid'){//ar

c# - Linq Query 一直抛出 "Unable to create a constant value of type System.Object....",为什么?

以下是代码示例:privatevoidloadCustomer(intcustIdToQuery){vardbContext=newSampleDB();try{varcustomerContext=fromtindbContext.tblCustomers//keepsthrowing:wheret.CustID.Equals(custIdToQuery)//Unabletocreateaconstantvalueoftype'System.Object'.selectnew//Onlyprimitivetypes('suchasInt32,String,andGuid'){//ar

c# - 无法将类型为 'System.DBNull' 的对象转换为类型 'System.String`

我的应用程序出现了上述错误。这是原始代码publicstringGetCustomerNumber(Guidid){stringaccountNumber=(string)DBSqlHelperFactory.ExecuteScalar(connectionStringSplendidmyApp,CommandType.StoredProcedure,"GetCustomerNumber",newSqlParameter("@id",id));returnaccountNumber.ToString();}我替换为publicstringGetCustomerNumber(Guidid

c# - 无法将类型为 'System.DBNull' 的对象转换为类型 'System.String`

我的应用程序出现了上述错误。这是原始代码publicstringGetCustomerNumber(Guidid){stringaccountNumber=(string)DBSqlHelperFactory.ExecuteScalar(connectionStringSplendidmyApp,CommandType.StoredProcedure,"GetCustomerNumber",newSqlParameter("@id",id));returnaccountNumber.ToString();}我替换为publicstringGetCustomerNumber(Guidid

c# - 如何使用 System.Net.HttpClient 发布复杂类型?

我有一个自定义的复杂类型,我想使用WebAPI来处理它。publicclassWidget{publicintID{get;set;}publicstringName{get;set;}publicdecimalPrice{get;set;}}这是我的WebAPIController方法。我想像这样发布这个对象:publicclassTestController:ApiController{//POST/api/testpublicHttpResponseMessagePost(Widgetwidget){widget.ID=1;//hardcodedfornow.TODO:Savet