草庐IT

run_list

全部标签

c# - List.Any 得到匹配的字符串

FilePrefixList.Any(s=>FileName.StartsWith(s))我可以在这里获取s值吗?我想显示匹配的字符串。 最佳答案 Any仅确定是否存在匹配项,除bool外不返回任何内容它需要执行查询。您可以使用Where或First/FirstOrDefault:stringfirstMastch=FilePrefixList.FirstOrDefault(s=>FileName.StartsWith(s));//nullifnomatchvarallMatches=FilePrefixList.Where(s=>

C# Linq - 无法将 IEnumerable<string> 隐式转换为 List<string>

我有一个这样定义的列表:publicListAttachmentURLS;我正在像这样向列表中添加项目:instruction.AttachmentURLS=curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment=>!String.IsNullOrEmpty(Attachment));但我收到此错误:无法将IEnumerable隐式转换为列表我做错了什么? 最佳答案 Where方法返回IEnumerable.尝试添加.ToLis

c# - c#中list<>和dictionary<>有什么区别

我对c#中的列表和字典有一个奇怪的疑问在列表中,我们使用以下方法将项目添加到列表usingSystem.Collections.Generic;classProgram{staticvoidMain(){Listlist=newList();list.Add(2);list.Add(3);list.Add(5);list.Add(7);}}在字典中我们添加这样的项目......usingSystem;usingSystem.Collections.Generic;classProgram{staticvoidMain(){Dictionaryd=newDictionary();d.Ad

c# - List.Sort(自定义排序...)

我有一个包含3个项目的List对象:Partial、FullToH和FullToO。我将此列表绑定(bind)到aspOptionButtonList,并按字母顺序对其进行排序。但是,我想按如下方式对列表进行排序:全到H,部分,全到O。我怎样才能做到这一点? 最佳答案 Linq对此非常有用。您甚至可以构建顺序序列以动态定义它,因为直到ToList才执行排序。varsortedList=yourList.OrderBy(i=>i.FullToH).ThenBy(i=>i.Partial).ThenBy(i=>i.FullToO).To

c# - 如何将 XML 转换为 List<string> 或 String[]?

如何将以下XML转换为List或String[]:12 最佳答案 听起来您更多的是在解析之后而不是完整的XML序列化/反序列化。如果您可以使用LINQtoXML,这将非常简单:usingSystem;usingSystem.Linq;usingSystem.Xml.Linq;publicclassTest{staticvoidMain(){stringxml="12";XDocumentdoc=XDocument.Parse(xml);varlist=doc.Root.Elements("id").Select(element=>e

c# - 如何在一行 C# 3.0 中将 object[] 转换为 List<string>?

好吧,我放弃了,你如何在一行中做到这一点?publicobjectConvert(object[]values,TypetargetType,objectparameter,System.Globalization.CultureInfoculture){//Listfields=values.ToList();//Listfields=valuesasList;//Listfields=(List)values;Listfields=newList();foreach(objectvalueinvalues){fields.Add(value.ToString());}//proce

c# - 懒惰<T> : "The function evaluation requires all threads to run"

我有一个带有一些静态属性的静态类。我在一个静态构造函数中初始化了所有这些,但后来意识到这是浪费,我应该在需要时延迟加载每个属性。所以我转而使用System.Lazytype来完成所有肮脏的工作,并告诉它不要使用它的任何线程安全功能,因为在我的例子中执行总是单线程的。我得到了以下类(class):publicstaticclassQueues{privatestaticreadonlyLazyg_Parser=newLazy(()=>newQueue(Config.ParserQueueName),false);privatestaticreadonlyLazyg_Distributor

c# - "long-running tasks"是什么意思?

Bydefault,theCLRrunstasksonpooledthreads,whichisidealforshort-runningcompute-boundwork.Forlonger-runningandblockingoperations,youcanpreventuseofapooledthreadasfollows:Tasktask=Task.Factory.StartNew(()=>...,TaskCreationOptions.LongRunning);我正在阅读有关thread和task的主题。你能给我解释一下什么是“长时间运行”和“短期运行”任务吗?

c# - 使用 `async` lambda 和 `Task.Run()` 是多余的吗?

我刚遇到一些代码,例如:vartask=Task.Run(async()=>{awaitFoo.StartAsync();});task.Wait();(不,我不知道Foo.StartAsync()的内部工作原理)。我最初的react是摆脱async/await并重写为:vartask=Foo.StartAsync();task.Wait();这是否正确(同样,对Foo.StartAsync()一无所知)。This回答Whatdifferencedoesitmake-runningan'async'actiondelegatewithaTask.Run...似乎表明在某些情况下它可能有

c# - 将 List<KeyValuePair<string, string>> 序列化为 JSON

我是JSON的新手,请帮忙!我正在尝试序列化List>作为JSON目前:[{"Key":"MyKey1","Value":"MyValue1"},{"Key":"MyKey2","Value":"MyValue2"}]预期:[{"MyKey1":"MyValue1"},{"MyKey2":"MyValue2"}]我引用了this中的一些示例和this.这是我的KeyValuePairJsonConverter:JsonConverterpublicclassKeyValuePairJsonConverter:JsonConverter{publicoverridevoidWriteJs