草庐IT

followers_count

全部标签

c# - 当 IsEmpty == true 时,为什么 ConcurrentQueue<T>.Count 不返回 0?

我在JamesMichaelHare'sblog上阅读了有关.NET4中新的并发集合类的信息,和pagetalkingaboutConcurrentQueue说:It’sstillrecommended,however,thatforemptychecksyoucallIsEmptyinsteadofcomparingCounttozero.我很好奇-如果有理由使用IsEmpty而不是将Count与0进行比较,为什么该类在执行任何昂贵的计数工作之前不在内部检查IsEmpty并返回0?例如:publicintCount{get{//CheckIsEmptysowecanbailoutqu

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# - SQL 日期问题 : How to get Yesterdays date in the following formatte

这是我目前的情况declare@TodaysmalldatetimeSet@Today=GETDATE()select@Todayyield2011-03-1013:46:00我需要的是:2011-03-09 最佳答案 试试这个:SELECTREPLACE(CONVERT(VARCHAR,DATEADD(dd,-1,GETDATE()),102),'.','-')GETDATE()返回当前日期/时间。DATEADD(dd,-1,GETDATE())从当前日期/时间减去一天。CONVERT(VARCHAR,@DATE,102)将日期转

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# - 协变/逆变 : how to make the following code compile

更新:以下代码仅在C#4.0(VisualStudio2010)中有意义看来我对协变/逆变有一些误解。谁能告诉我为什么以下代码无法编译?publicclassTestOne{publicIEnumerableMethod(IEnumerablevalues)whereTDerived:TBase{returnvalues;}}编译时:(!!!)publicinterfaceIBase{}publicinterfaceIDerived:IBase{}publicclassTestTwo{publicIEnumerableMethod(IEnumerablevalues){returnva

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# - 多线程,Task.Run 错误 'The call is ambiguous between the following methods or properties'

当我尝试构建项目时,显示以下错误消息。Thecallisambiguousbetweenthefollowingmethodsorproperties:'System.Threading.Tasks.Task.Run(System.Action)'and'System.Threading.Tasks.Task.Run(System.Func)'我该如何解决这个问题?publicstaticclassMaintananceManager{privatestaticThreadSafeSocialMediaListPostList=newThreadSafeSocialMediaList(

c# - DataGridView RowCount 与 Rows.Count

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