草庐IT

Peek-and-select

全部标签

C# : Implicit conversion between '<null>' and 'bool'

当我尝试转换object时收到奇怪的错误消息至bool,这是我的代码:publicpartialclassModifierAuteur:DevExpress.XtraEditors.XtraForm{publicModifierAuteur(objectgetKeyDecesCheckBox){decesCheckBox.Checked=getKeyDecesCheckBox==null?null:(bool)getKeyDecesCheckBox;}}这是错误信息:Typeofconditionalexpressioncannotbedeterminedbecausethereisn

c# - 数据表Select语句问题

下面的VB行,其中_DSversionInfo是一个数据集,不返回任何行:_DSversionInfo.Tables("VersionInfo").Select("FileID=88")但检查显示该表包含FileID为92、93、94、90、88、89、215、216的行。表列均为字符串类型。进一步调查表明,使用88、215和216的ID只会返回引用数字的行。即_DSversionInfo.Tables("VersionInfo").Select("FileID='88'")无论数字是否被引用,所有其他行都有效。有人能解释为什么某些数字会发生这种情况而其他数字不会发生这种情况吗?我明白

c# - 递归 LINQ 查询 : select item and all children with subchildren

有没有什么方法可以编写一个LINQ(或过程式)查询,它可以通过一个查询选择一个项目和所有子项?我有实体:publicclassComment{publicintId{get;set;}publicintParentId{get;set;}publicintText{get;set;}}我有一个ID,所以我想选择带有ID的Comment及其所有子项和子项。示例:1-2--3-4-5--623如果ID==1那么我想要1,2,3,4,5,6的列表。 最佳答案 publicclassComment{publicintId{get;set;}

c# - 遍历 "selected"枚举值?

这个问题在这里已经有了答案:HowtoiterateovervaluesofanEnumhavingflags?(18个答案)关闭6年前。我知道如何遍历属性的枚举列表,但我将如何遍历所有“选定的”枚举属性?例如,如果一个人做了Prop1|Prop2反对publicenumFoo{Prop1;提案2;Prop3,我该如何实现?这是我现在拥有的:varvalues=Enum.GetValues(typeof(FileStatus)).Cast();foreach(varvalueinvalues){}它遍历所有枚举属性,但我只想循环那些被“选中”的属性。更新:[Flags]属性已设置。更新

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

c# - 在 Select 和 Where 调用中重用 Linq to Entities 的 Expression<Func<T, TResult>

假设我有一个实体对象定义为publicpartialclassArticle{publicId{get;set;}publicText{get;set;}publicUserId{get;set;}}根据文章的某些属性,我需要确定给定用户是否可以删除该文章。所以我添加了一个静态方法来进行检查。像这样的东西:publicpartialclassArticle{publicstaticExpression>CanBeDeletedBy(intuserId){//Addlogictobereusedherereturna=>a.UserId==userId;}}现在我可以做using(MyE

c# - "nested if"与使用 F# 的 "if and"性能

以下代码导致slow1=1323ms、slow2=1311ms和fast=897ms。这怎么可能?此处:Nestedornotnestedif-blocks?他们提到Anymoderncompiler,andbythatImeananythingbuiltinthepast20years,willcompilethesetothesamecode.lets=System.Diagnostics.Stopwatch()letmutablea=1s.Start()foriin0..1000000000doifi 最佳答案 我已经从ild

c# - 动态、linq 和 Select()

考虑以下(无意义,但用于说明目的)测试类:publicclassTest{publicIEnumerableToEnumerableStrsWontCompile(IEnumerablet){returnt.Select(x=>ToStr(x));}publicIEnumerableToEnumerableStrsWillCompile(IEnumerablet){varres=newList();foreach(vardint){res.Add(ToStr(d));}returnres;}publicstringToStr(dynamicd){returnnewstring(d.Ge

c# - DDD : entity's collection and repositories

假设我有publicclassProduct:Entity{publicIListItems{get;set;}}假设我想找到一个最大的项目...我可以添加方法Product.GetMaxItemSmth()并使用Linq(fromiinItemsselecti.smth).Max())或使用手动循环或其他方式。现在,问题是这会将整个集合加载到内存中。正确的解决方案是进行特定的数据库查询,但域实体无权访问存储库,对吧?所以要么我做productRepository.GetMaxItemSmth(product)(这很丑,不是吗?),或者即使实体可以访问存储库,我也使用来自实体的IPro

c# - IEnumerable.Select() 可以跳过一个项目吗?

我有这个功能:publicIEnumerableEnumPrograms(){returndev.AudioSessionManager2.Sessions.AsEnumerable().Where(s=>s.GetProcessID!=0).Select(s=>{try{returnProcess.GetProcessById((int)s.GetProcessID).ProcessName;}catch(ArgumentException){returnnull;}});}try..catch是必需的,因为可能存在具有不再存在的PID的session。我想跳过它们。有没有办法从Se