草庐IT

equal_to

全部标签

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# - LINQ 到 XML : How to select the next element

我有一个来自iPhone应用程序的plist文件。它看起来像下面这样:barcodesJF893J89FJ-66666JF893J89FJ-55555currentStep1dateFinished2010-05-10T18:33:25ZdateStarted2010-05-10T18:33:25ZdescriptionTESTgeoRequiredNinProgressNjobID10085jobStepslabelTESTresponsematthudsonstepID1103typeID4我需要在jobSteps之后获取数组。到目前为止我有这个:XDocumentxml=XDoc

c# - WPF/银光 : How to convert hex value into Color?

我知道如何创建蓝色的SolidColorBrush并在转换器中像这样返回它:returnnewSolidColorBrush(Colors.Blue);但是,如果我需要SolidColorBrush具有此十六进制值怎么办?#44FFFF00?我该怎么做?谢谢, 最佳答案 newSolidColorBrush(Color.FromArgb(0x44,0xFF,0xFF,0));(Documentation)注意:如果您的代码将在Silverlight和WPF中共享,请不要使用Color.FromRgb()(没有A),因为Silverl

c# - .Equals 上的 C# 泛型方法中的意外行为

为什么Equals方法返回的结果与泛型方法不同?我认为这里有一些我不明白的自动装箱。这是一个重现.net3.5或4.0行为的示例:staticvoidMain(string[]args){TimeZoneInfotzOne=TimeZoneInfo.Local;TimeZoneInfotzTwo=TimeZoneInfo.FindSystemTimeZoneById(tzOne.StandardName);Console.WriteLine(Compare(tzOne,tzTwo));Console.WriteLine(tzOne.Equals(tzTwo));}privatestat

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

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

c# - LINQ to XML 可选元素查询

我正在处理一个现有的XML文档,它的结构(部分)如下:Bob1Larry我正在使用LINQtoXML查询XDocument以检索所有这些条目,如下所示:varitems=fromginxDocument.Root.Descendants("Group").Elements("Entry")selectnew{name=(string)g.element("Name").Value,id=g.Elements("ID").Count()>0?(string)g.Element("ID").Value:"none"};“ID”元素并不总是存在,所以我的解决方案是上面的Count()爵士乐。

c# - ASP.Net Core 2 错误处理 : How to return formatted exception details in Http Response?

我正在寻找一种方法来返回调用我的WebAPI的方法时发生的任何异常的详细信息。默认情况下,在生产环境中,错误500“InternalServerError”是API返回的唯一信息。它是一个不在互联网上发布的私有(private)API,调用方应用程序需要获取并存储所有详细信息以防出现异常。异常详细信息可以在HttpResponse内容中采用JSON格式,允许调用者阅读消息属性,以及异常的StackTraceString属性(没有类似UseDeveloperExceptionPage配置的HTTP页面)。目前默认的启动配置方法是:publicclassStartup{[...]publi

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# - 转换为日期时间 : how to set format

我像这样使用转换:Convert.ToDateTime(value)但我需要将日期转换为类似“mm/yy”的格式。我正在寻找这样的东西:varformat="mm/yy";Convert.ToDateTime(value,format) 最佳答案 您可能应该使用DateTime.ParseExact或DateTime.TryParseExact反而。它们允许您指定特定格式。我个人更喜欢Try版本,因为我认为它们会为错误情况生成更好的代码。 关于c#-转换为日期时间:howtosetfor

c# - TaskCompletionSource 抛出 "An attempt was made to transition a task to a final state when it had already completed"

我想使用TaskCompletionSource来包装MyService这是一个简单的服务:publicstaticTaskProcessAsync(MyServiceservice,intparameter){vartcs=newTaskCompletionSource();//EverytimeProccessAsynciscalledthisassignstoCompleted!service.Completed+=(sender,e)=>{tcs.SetResult(e.Result);};service.RunAsync(parameter);returntcs.Task;}