草庐IT

distinct-values

全部标签

c# - 打开可空 bool 值 : case goes to null when value is true

我意识到处理可空类型的正确方法是使用HasValue属性。但我想知道为什么以下switch语句会在null情况下而不是默认情况下中断。使用VS2015C#4.0。另一台使用VS2010C#4.0的计算机没有同样的问题。privatevoidTesting(){bool?boolValue=true;switch(boolValue){casenull:break;//eventhoughvalueistrue,coderunsheredefault:break;}}编辑:观察到任何Nullable的行为如果只有caseNull和default已指定。 最佳答

c# - 如何在 Linq to SQL 中使用 distinct 和 group by

我正在尝试将以下sql转换为Linq2SQL:selectgroupId,count(distinct(userId))fromprocessroundissueinstancegroupbygroupId这是我的代码:varq=fromiinProcessRoundIssueInstancegroupibyi.GroupIDintogselectnew{Key=g.Key,Count=g.Select(x=>x.UserID).Distinct().Count()};当我运行代码时,我不断收到无效的GroupID。有任何想法吗?似乎distinct把事情搞砸了..这里是生成的sql:

c# - CodeContracts : Boolean condition evaluates to a constant value, 为什么?

我收到此警告但无法找出问题...CodeContracts:warning:TheBooleanconditiond1.Count!=d2.Countalwaysevaluatestoaconstantvalue.Ifit(oritsnegation)appearinthesourcecode,youmayhavesomedeadcodeorredundantcheck代码如下:publicstaticboolDictionaryEquals(IDictionaryd1,IDictionaryd2){if(d1==d2)returntrue;if(d1==null||d2==null)

c# - 在 Linq-To-Sql 中避免 "Nullable object must have a value."

我有一个这样的方法查询:publicIListGetBusinessObject(Guid?filterId){using(vardb=newL2SDataContext()){varresult=fromboindb.BusinessObjectswhere(filterId.HasValue)?bo.Filter==filterId.value:trueorderbybo.NameselectSqlModelConverters.ConvertBusinessObject(bo);returnresult.ToList();}}在运行时,这会抛出一个System.InvalidOp

c# - GetMonthName : Valid values are between 1 and 13, 包括在内。为什么?

我不小心将0传递给DateTimeFormatInfo的GetMonthName方法:DateTimeFormatInfoinfo=newDateTimeFormatInfo();varmonthName=info.GetMonthName(0);并得到一个System.ArgumentOutOfRangeException错误消息:有效值在1到13之间,包括在内。传入1到12将返回“January”到“December”,但传入13将返回一个空字符串。我明白为什么月份数字不是零索引的,但是第13个月是做什么用的? 最佳答案 这是因

c# - 将 DBNull.Value 和空文本框值传递给数据库

这个问题在这里已经有了答案:HowdoIParameterizeanullstringwithDBNull.Valueclearlyandquickly(8个答案)关闭8年前。我的页面上有一些文本框可以为空,因为它们是可选的,而且我有这个DAL代码parameters.Add(newSqlParameter("@FirstName",FirstName));parameters.Add(newSqlParameter("@LastName",LastName));parameters.Add(newSqlParameter("@DisplayName",DisplayName));pa

c# - 从具有 Distinct/GroupBy 的 IEnumerable 中选择并排序——可能吗?

假设你有这个:classLogEntry{intID;intUserName;datetimeTimeStamp;stringDetails;}并且您已经提取了一组这样的数据:IDUsernameTimestampDetails1foo1/01/2010Accountcreated2zip2/02/2010Accountcreated3bar2/02/2010Accountcreated4sandwich3/03/2010Accountcreated5bar5/05/2010Stolefood6foo5/05/2010Can'tfindfood7sandwich8/08/2010Don

c# - 流利的断言 : Assert one OR another value

使用流畅的断言,我想断言给定的字符串包含两个字符串之一:actual.Should().Contain("oneWay").Or().Should().Contain("anotherWay");//eitervalueshouldpasstheassertion.//forexample:"youmaydoitoneWay."shouldpass,but//"youmaydoitthisWay."shouldnotpass只有当两个值都不包含时,断言才会失败。这不起作用(甚至无法编译),因为没有Or()运算符。我现在是这样做的:boolisVariant1=actual.Contai

c# - 通过显式本地化获取资源值(value)

对于不同的资源文件(*.resx),如何通过显式本地化来检索本地化值。也就是说,通常我可以直接引用带有custom-tool-namespace.Resource.localizedAttribute的属性。它将提供的值取决于为CurrentCulture设置的本地化(线程方式)。但与此不同的是,我想将本地化交给资源getter。这可能吗? 最佳答案 假设你有多个资源文件:Messages.resxMessages.fr-FR.resx...Messages.xx-XX.resx都包含一些字符串值,您可以检索特定文化的值:varcu

c# - Dictionary.Values.ToArray() 的顺序是什么?

如果我向字典中添加值,然后在代码中的某处添加值,我想使用以下方法将该字典转换为数组:myDictionary.Values.ToArray()数组会按照我输入的顺序出来吗?还是在某个阶段排序? 最佳答案 如果你想对值进行排序(在键上),那么你应该使用SortedDictionary或SortedList对于普通的字典,值的顺序是依赖于实现的,但您也可以假设它是随机的。输入顺序丢失。 关于c#-Dictionary.Values.ToArray()的顺序是什么?,我们在StackOverf