草庐IT

non_blank_count

全部标签

c# - dot net 是否有像 IEnumerable 这样带有 Count 属性的接口(interface)?

dotnet是否有像IEnumerable这样带有计数属性的接口(interface)?我知道IList和ICollection等接口(interface)确实提供了Count属性,但似乎这些接口(interface)首先是为可变数据结构设计的,用作只读接口(interface)似乎是事后才想到的——存在IsReadOnly字段和mutators抛出异常当此属性为真时,IMO对此提供了充分的证据。目前我正在使用一个名为IReadOnlyCollection的自定义接口(interface)(请参阅我自己对这篇文章的回答),但我很高兴知道其他替代方法。 最佳答

c# - 起订量参数 TargetParameterCountException : Parameter count mismatch Exception

以下是我的通用基础存储库界面publicinterfaceIRepository{IQueryableAllIncluding(paramsExpression>[]includeProperties);}我的实体publicclassSdk{publicSdk(){this.Identifier=Guid.NewGuid().ToString();}publicvirtualICollectionAccessibleResources{get;set;}publicstringIdentifier{get;set;}}下面是具体的repopublicinterfaceISdkRepo

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

c# - c# 编译器是否优化 Count 属性?

Listlist=...for(inti=0;i那么编译器是否知道list.Count不必每次迭代都调用? 最佳答案 你确定吗?Listlist=newList{0};for(inti=0;i如果编译器缓存了上面的Count属性,list的内容将是0和1。如果没有缓存,内容将是从0到100.现在,这对您来说可能看起来像是一个人为的例子;但是这个呢?Listlist=newList();inti=0;while(list.Count这两个代码片段似乎完全不同,但这只是因为我们倾向于思考for循环与while循环。在任何一种情况下,每次

c# - Entity Framework : Alternate solution to using non primary unique keys in an association

我知道EntityFramework不允许您使用非主唯一键作为外键关联从数据库生成模型。我可以手动修改EDMX吗?如果是这样,有人可以给我一个例子或引用吗?如果不是,还有其他可能吗?最简单的例子:这是表的DDL。您会注意到我有一个从PersonType.TypeCode到Person.TypeCode的外键CREATETABLE[dbo].[PersonType]([PersonTypeId][int]NOTNULL,[TypeCode][varchar](10)NOTNULL,[TypeDesc][varchar](max)NULL,CONSTRAINT[PK_PersonType]

c# - 应该避免 IEnumerable 的 Count() 吗?

通常,我使用List,然后在我不再需要更新它们时将它们作为IEnumerable返回。但是,我遇到了一个问题,我实际上需要枚举它们但首先需要知道计数。IEnumerable会枚举每个项目并找到计数(O(N)),还是会依赖于List的Count属性(O(1))?此外,如果IEnumerable是LINQ查询的结果怎么办? 最佳答案 WillIEnumerableenumerateeveryitemandfindthecount(O(N)),orwillitrelyonList'sCountproperty(O(1))?它将使用Coun

c# - 如何从 SqlDataReader 读取 SQL Server COUNT

我正在尝试使用C#SqlDataReader查找表的计数,但我一直在获取invalidattempttoreadwhennodataispresent我的代码:stringsql="SELECTCOUNT(*)FROM[DB].[dbo].[myTable]";SqlCommandcmd=newSqlComman(sql,connectionString);SqlDataReadermySqlDataReader=cmd.ExecuteReader();intcount=mySqlDataReader.GetInt32(0);//HereiswhereIgettheerror.我知道我

c# - 低级差异 : non-static class with static method vs. 静态类与静态方法

我想知道使用具有静态方法的非静态类与具有相同静态方法的静态类的一般好处(或缺点)是什么,除了我不能使用非静态类中的静态方法作为扩展方法。例如:classNonStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromanon-staticclass.";}}与此相比:staticclassStaticClass{publicstaticstringGetData(){return"Thiswasinvokedfromastaticclass.";}}使用一种方法优于另一种方法对性能/内存有何影响?注意:假设我不需要

c# - DataGridView RowCount 与 Rows.Count

如果我有一个DataGridViewuxChargeBackDataGridView。以下是否在语法上不同但实际上是相同的?:intnumRows=uxChargeBackDataGridView.Rows.Count;intnumRowCount=uxChargeBackDataGridView.RowCount;如果uxChargeBackDataGridView为空则两者都等于1;因此,如果其中任何一个等于1,我可以假设用户没有输入任何数据,这是否符合逻辑?我的WinForms应用程序有一个名为RUN的按钮-我可以使用上面的测试来确定是否启用此按钮,即仅在numberofrows

c# - IEnumerable<T>.Count 在哪些情况下进行了优化?

使用reflector我注意到System.Linq.Enumerable.Count方法中有一个条件可以针对IEnumerable的情况对其进行优化。passed实际上是一个ICollection.如果转换成功,Count方法不需要遍历每个元素,而是可以调用ICollection的Count方法。基于此,我开始认为IEnumerable可以像集合的只读View一样使用,而不会出现我最初基于IEnumerable的API预期的性能损失我感兴趣的是是否优化了CountIEnumerable时仍然成立是Select的结果关于ICollection的声明,但根据反射(reflect)的代码,