草庐IT

is_object

全部标签

c# - 为什么 List<double> 显式转换为 IEnumerable<object> 会抛出异常?

根据这个MSDNreferenceIEnumerable是协变的,这可以将对象列表隐式转换为可枚举对象:IEnumerablestrings=newList();IEnumerableobjects=strings;在我自己的代码中,我写了一行代码,当列表的项目类型是Point类时,它可以完美运行(Point是一个简单的类,具有三个双x、y、z属性):varobjects=(IEnumerable)dataModel.Value;//herepropertyValueisalistthatcouldbeofanytype.但是当列表的项类型为double时,上面的代码返回以下异常:Un

c# - 无法使用实例引用访问成员 'object.Equals(object, object)';用类型名称限定它

当我在C#中使用以下代码时...inttotalValue=0;inttotal=0;totalValue=int.Parse(Session["price"].ToString())*int.Parse(Session["day"].ToString());//ThislinecausestheerrortotalValue+=Session["IsChauffeurUsed"].ToString().Equals("Yes",StringComparer.CurrentCultureIgnoreCase)?80:0;...我收到此错误:Member'object.Equals(ob

c# - 在 C# 中抑制 "Member is never assigned to"警告

我有以下代码:ViewPortViewModel_Trochoid;publicViewPortViewModelTrochoid{get{return_Trochoid;}set{this.RaiseAndSetIfChanged(value);}}使用ReactiveUIINPC支持。编译器总是警告我Trochoid永远不会分配给并且永远为空。然而,由于RaiseAndSetIfChanged通过CallerMemberName支持执行的魔法,代码确实有效,但编译器是错误的。我如何干净地在我的代码中抑制这些警告? 最佳答案 Ho

c# - HttpClient : The uri string is too long

鉴于以下尝试将数据发布到生成PDF文件的Web服务,PDFrocket(顺便说一下,这很棒)。我收到错误消息无效的URI:uri字符串太长为什么有人会对POSTed数据强加任意限制?using(varclient=newHttpClient()){//Buildtheconversionoptionsvaroptions=newDictionary{{"value",html},{"apikey",ConfigurationManager.AppSettings["pdf:key"]},{"MarginLeft","10"},{"MarginRight","10"}};//THISLI

c# - LINQ to Entities 无法识别方法 'Int32 ToInt32(System.Object)' 方法,并且无法将此方法翻译成存储表达式

这是我正在尝试做的事情:publicListGetRolesForAccountByEmail(stringemail){varaccount=db.Accounts.SingleOrDefault(a=>a.Email==email);if(account==null)returnnewList();returndb.AccountRoles.Where(a=>a.AccountId==account.AccountId).Select(a=>Convert.ToInt32(a.RoleId)).ToList();}我必须转换为Int32,因为我无法返回List当方法返回List时.

c# - 试图允许空值但是... "Nullable object must have a value"

我试图在我的下拉列表中允许空值,在我的数据库表中我已经为特定的int字段设置了允许空值,但是当我运行代码时我收到错误消息“可为空的对象必须有一个值”,我认为问题可能出在ModelState中。Controller[HttpPost]publicActionResultEdit(Studentstudent){if(ModelState.IsValid){db.Entry(student).State=EntityState.Modified;db.SaveChanges();Loanw=newLoan(){StudentID=student.StudentID,ISBN=student

c# - 序列化异常 : Type is not resolved for member "..."

我一直在尝试将程序集动态加载到AppDomain。我需要这样做是因为我想动态调用一个方法,但在我的应用程序运行时不要保留DLL的句柄,以便在需要时可以替换它。但我收到此SerializationException异常:类型未解析成员“...”这是我的代码:AppDomaindomain=AppDomain.CreateDomain("TempAppDomain",null,AppDomain.CurrentDomain.SetupInformation);try{objectobj=domain.CreateInstanceFromAndUnwrap(dllPath,typeName)

c# - 新手 LINQ 问题 : Is Paging in LINQ Queries Possible?

是否可以在Linq查询中使用“分页”功能?假设我有一些这样的XML:ChoiceOneChoiceTwoChoiceThree...ChoiceForty-EightChoiceForty-NineChoiceFifty如果我想实现分页功能,我是否能够为LINQ查询提供一个偏移量,以便我可以从第11个元素开始并在第20个元素结束?如果是这样,如果数据是对象列表而不是XML,查询会有什么不同吗? 最佳答案 varq=fromXinChoices.Skip((page-1)*pageSize).Take(pageSize)selectX

c# - 将 List<object> 转换为 List<Type>,类型在运行时已知

我正在实现某种反序列化并遇到下一个问题:我有List和System.Reflection.Field,它是FieldType可以是List,List或List,所以我需要从List转换到那种类型。publicstaticobjectConvertList(Listvalue,Typetype){//typemaybeList,List,List}我可以单独写每个案例,但应该有更好的方法使用反射。 最佳答案 我相信你想要的是:publicstaticobjectConvertList(Listvalue,Typetype){varco

c# - 公开课 - "is inaccessible due to its protection level. Only public types can be processed."

我正在做一个测试项目来了解对象的XML序列化,但我遇到了一个奇怪的运行时错误:namespaceSerializeTest{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidserializeConnection(Connconnection){XmlSerializerserializer=newXmlSerializer(typeof(Conn));TextWritertextWrit