草庐IT

List_of_segments

全部标签

c# - 误报 : Fix this implementation of IDisposable to conform to the dispose pattern

我的类实现了IDisposable并遵循了的模式publicvoidDispose(){Dispose(true);GC.SuppressFinalize(this);}但sonar仍然告诉我需要实现处置模式...https://sonarqube.com/issues#issues=AVtsPLjmtpYg8Dj4z0MU这是Sonar的缺陷还是我遗漏了什么? 最佳答案 我看到你已经解决了这个问题,但如果其他人有同样的问题,我会详细说明规则要求。这条规则的想法是允许潜在的派生类正确地处理你的类的成员。因此,如果您的类是密封的,则该

C# - 当 Dog 是 Animal 的子类时,如何将 List<Dog> 转换为 List<Animal>?

我有一个类Animal,及其子类Dog.我有一个List我想添加一些List的内容到List.有没有比只投List更好的方法呢?到List,然后使用AddRange? 最佳答案 如果您使用的是C#4,则不需要转换:Listanimals=newList();Listdogs=newList();animals.AddRange(dogs);这是允许的,因为AddRange()接受IEnumerable,即covariant.如果您没有C#4,那么您将不得不迭代List并转换每个项目,因为协方差只是在那时添加。您可以通过.Cast完成

c# - 防止重复的 List<T> 条目

我希望我能够解决这个问题,但我终其一生都无法理解为什么这段代码无法正常运行并允许将重复的条目添加到列表中。永远不会满足if语句条件,即使我从同一位置拖入相同的文件也是如此。我不明白为什么“包含”方法不匹配它们。publicclassForm1:Form{privateListdragDropFiles=newList();privatevoidForm1_DragDrop(objectsender,DragEventArgse){try{if(e.Data.GetDataPresent(DataFormats.FileDrop)){string[]files=(string[])e.D

c# - 在等待 List<Task> 中的所有任务完成时显示进度

我目前正在尝试在一行的末尾连续打印点作为不确定进度的一种形式,同时运行大量任务,使用以下代码:start=DateTime.Now;Console.Write("*Processingvariables");TaskentireTask=Task.WhenAll(tasks);Taskprogress=newTask(()=>{while(!entireTask.IsCompleted){Console.Write(".");System.Threading.Thread.Sleep(1000);}});progress.Start();entireTask.Wait();timeDi

c# - 为什么 List<T> 不实现 IOrderedEnumerable<T>?

我想使用有序的枚举,并使用接口(interface)作为返回类型而不是具体类型。我需要返回一组有序的对象。但是,当使用IList时执行我不能返回IOrderedEnumerable,作为IList不继承IOrderedEnumerable。在下面的示例中,我有一个带有系列存储库的View模型,实现为List。系列对象,因为它们位于List中。,下令。我是一个访问器方法,我想返回经过过滤的系列集合,其中仅返回特定类型的系列对象,同时保持过滤元素之间的原始顺序。//////Representstheviewmodelforthismodule.///publicclassViewModel

c# - 按对象的属性对 List 中的对象进行排序

我有一个C#中的对象列表。所有对象都包含属性code1和code2(以及其他属性)。对象列表没有特定顺序。我需要按对象的code1和code2属性对对象列表进行排序。例子:List->object=id,name,code1,code2,hours,amount.示例代码1=004示例代码2=001、002、003、004、016示例代码1=005示例代码2=001,002,003,004所以在排序后我希望对象按以下顺序004001004002004003004005004016005001005002005003005004 最佳答案

c# - 如何将 JSON 数组转换为 List<>?

这是我的json,我需要访问出勤数组中每个对象下的值:{"name":"","course":"","attendance":[{"name":"INTERNATIONALFINANCE","type":"Theory","conducted":"55","present":"50"},{"name":"INDIANCONSTITUTION","type":"Theory","conducted":"6","present":"6"}]}这是我的代码:publicclassAtt{publicclassAttendance{publicstringname{get;set;}publi

c# - 错误 : A project with an out put type of class library

我试图找出.net并得到这段代码,当我尝试从VS2008运行时它给我这个错误AprojectwithanOutputTypeofClassLibrarycannotbestarteddirectly.Inordertodebugthisproject,addanexecutableprojecttothissolutionwhichreferencestothelibraryproject.Settheexecutableprojectasthestartupproject我正在学习C#,所以不知道该做什么 最佳答案 您不能运行库。

c# - 将 EnumerableRowCollection<string> 转换为 List<string>

我试图在一个函数中返回这个集合:Listcodes=(fromqinData.AsEnumerable()selectq.Field("START"));returncodes;这会引发错误:Cannotimplicitlyconverttype'System.Data.EnumerableRowCollection'to'System.Collections.Generic.List'返回此类集合的最佳方式是什么? 最佳答案 自EnumerableRowCollection工具IEnumerable你可以只添加一个ToList()

c# - string.split() "Out of memory exception"读取制表符分隔文件时

我在我的C#代码中使用string.split()来读取制表符分隔的文件。我正面临下面代码示例中提到的“OutOfMemory异常”。这里我想知道为什么文件大小为16MB时会出现问题?这是正确的方法吗?using(StreamReaderreader=newStreamReader(_path)){//...........Loadthefirstlineofthefile................stringheaderLine=reader.ReadLine();MeterDataIPValueListobjMeterDataList=newMeterDataIPValueL