草庐IT

One-or-more

全部标签

c# - Linq 性能 : should I first use `where` or `select`

我在内存中有一个很大的List,来自一个具有大约20个properties的类。我想仅根据一个property过滤此列表,对于特定任务我只需要该property的列表。所以我的查询是这样的:data.Select(x=>x.field).Where(x=>x=="desiredvalue").ToList()先使用Select还是使用Where哪个性能更好?data.Where(x=>x.field=="desiredvalue").Select(x=>x.field).ToList()如果这与我将数据保存在内存中的数据类型或字段类型有关,请告诉我。请注意,我也需要这些对象来执行其他任

c# - 通用约束 : Can I test Equality of generic that can be a reference or value type?

我想要一个通用类,它可以接受引用类型或值类型,并且只执行基于相等性测试的操作。考虑以下几点:publicclassPropertywhereTProp:struct,IEquatable{publicTPropValue;publicvoidSetValue(ObservableObjectowner,TPropvalue){if(!Value.Equals(value))//cannotuse!=onstructconstrainedTProp{//...settheproperty}}}publicclassByRefPropertywhereTProp:class//Dontwa

c# - 温莎城堡 : Auto-register types from one assembly that implement interfaces from another

我使用CastleWindsor作为我的IoCcontainer.我有一个具有类似于以下结构的应用程序:MyApp.Services.dllIEmployeeServiceIContractHoursService...MyApp.ServicesImpl.dll员工服务:MyApp.Services.IEmployeeServiceContractHoursService:MyApp.Services.IContractHoursService...我使用XMLconfiguration目前,每次我添加一个新的IService/Service对时,我都必须向XML配置文件添加一个新组

No appropriate protocol (protocol is disabled or cipher suites are inappropriate)(Java版)

问题在访问MySQL时出现了,如下错误:javax.net.ssl.SSLHandshakeException:Noappropriateprotocol(protocolisdisabledorciphersuitesareinappropriate)Thefollowingrequiredalgorithmsmightbedisabled:SSLv3,TLSv1,TLSv1.1,RC4,DES,MD5withRSA,DHkeySize1024,ECkeySize224,3DES_EDE_CBC,anon,NULL,includejdk.disabled.namedCurves.Editth

c# - 发送邮件异步 : An asynchronous module or handler completed while an asynchronous operation was still pending

在使用SendMailAsync时出现以下错误:Anasynchronousmoduleorhandlercompletedwhileanasynchronousoperationwasstillpending我的代码:publicstaticasyncTaskSendEmail(MessageContentmessageContent,stringemailBody){SmtpClientsmtpClientNoSend=newSmtpClient();awaitsmtpClientNoSend.SendMailAsync(mailMessage);}来自Controller的调用:

c# - 系统参数异常 : Complex DataBinding accepts as a data source either an IList or an IListSource

我正在使用下面的C#代码来填充WinFormsListBox。但是我想隐藏所有系统文件夹。例如$RecyclingBin。但它给了我以下错误。System.ArgumentException:ComplexDataBindingacceptsasadatasourceeitheranIListoranIListSource.作为LINQ的新手,这让我很困惑。谁能告诉我哪里出错了?string[]dirs=Directory.GetDirectories(@"c:\");vardir=fromdindirswhere!d.StartsWith("$")selectd;listBox.Da

c# - 变量 : a Type or a keyword

MSDN将var归类到Types下。variablesthataredeclaredatmethodscopecanhaveanimplicittypevar“隐式类型var”在这种情况下是什么意思?严格来说,如果我有它可以向其他程序员解释。我能说吗?var是一个类型,或者我必须说;var是一个关键字,指示编译器自行确定类型。注意:这并不是要开始讨论var,也不是要学习var的使用。一劳永逸,我想确切地知道如何描述它,而msdn有点令人困惑,仅此而已。 最佳答案 var是contextualkeyword-连同yield,add和g

c# - "The type or namespace name ' 引用System.Xml.dll时XmlSerializer ' could not be found"错误

我已经在这上面浪费了几个小时:XmlSerializerserializer;是的,using在那里,引用在那里,我在VS2010中使用.NET4.0制作了整个解决方案,所以它不是那些东西。如果我进入对象资源管理器,我可以在正确的命名空间中找到我想要的XmlSerializer类,但是如果我尝试在我的代码文件中键入上面的行并进行编译,我会得到可怕的Thetypeornamespacename'XmlSerializer'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?)死亡警告。我也没有在Intelli

c# - 通缉 : DateTime. TryNew(year, month, day) or DateTime.IsValidDate(year, month, day)

标题基本上说明了一切。我从旧数据库(我无法更改)。目前,我使用以下代码将这些整数解析为DateTime结构:try{returnnewDateTime(year,month,day);}catch(ArgumentExceptionex){returnDateTime.MinValue;}有时,这些值并不代表有效日期(是的,用户输入了诸如1999-06-31之类的内容,但不,旧版应用程序并未对此进行验证)。自throwinganexceptionwhendatavalidationfailsisconsideredbadpractice,我更愿意用无异常代码替换它。然而,我能找到的唯一

c# -/平台 :anycpu32bitpreferred is not a valid setting for option/target:library or/target:module

我创建了一个Windows服务项目,后来决定将其输出类型更改为类库,这样我就可以将服务类包含在另一个项目中,该项目将创建要作为服务安装的.exe。但是现在,当我尝试构建第一个项目时,它失败并出现错误:/platform:anycpu32bitpreferredisnotavalidsettingforoption/target:libraryor/target:module我该如何解决这个问题? 最佳答案 尝试卸载项目(在解决方案资源管理器中右键单击)编辑.csproj(右键单击解决方案资源管理器)删除true重新加载项目。