草庐IT

get_object_list

全部标签

c# - 编辑 List<Tuple> 项

用List你可以用这个简单地编辑一个项目:varindex=List.FindIndex(s=>s.Number==box.Text);List[index]=newString;但是,如何将它应用于List>例如? 最佳答案 您可以用类似的方式找到索引-通过对列表中的每个元组应用条件:varindex=listOfTuples.FindIndex(t=>t.Item1==box1.Text||t.Item2==box2.Text);您可以通过调用Tuple.Create来替换一个项目:listOfTuples[index]=Tup

c# - C# : generate a list of two dimension arrays with the same shape 中的 FsCheck

假设我正在编写一些视频分析代码。这是视频类的简化版本:publicclassVideo{publicreadonlyintWidth;publicreadonlyintHeight;publicreadonlyListFrames;publicVideo(intwidth,intheight,IEnumerableframes){Width=width;Height=height;Frames=newList();foreach(varframeinframes){if(frame.GetLength(0)!=height||frame.GetLength(1)!=width){thr

c# - 枚举 MatchCollection 时,为什么 var 结果是 Object 类型而不是 Match 类型?

我注意到下面的代码有些奇怪:MatchCollectionmc=Regex.Matches(myString,myPattern);foreach(varmatchinmc)Console.WriteLine(match.Captures[0]);//变量match的类型是Object而不是Match。我习惯于使用var枚举集合,没有这样的问题。为什么MatchCollection不同? 最佳答案 MatchCollection是在.NET2之前编写的,所以它只是实现了IEnumerable而不是IEnumerable.但是,您可以

c# - 为什么我需要使用 get 和 set?

我有一段代码:publicclassMyClass{privatestring_myProperty;publicstringMyProperty{get{return_myProperty;}set{_myProperty=value;}}}这里有什么意义?我可以将_myProperty字符串声明为公共(public)字符串,我的任何类对象都可以直接访问它们并获取或设置值。相反,我们将_myProperty设为私有(private),并使用类对象使用get和set来访问它们。在任何一种情况下,类对象都能够访问它们并且结果总是相同的。那么为什么要使用这种方法呢?这仅仅是因为我可以在se

C# 排序列表 : How to get the next element?

我想知道如何获取C#排序列表中的下一个元素。到目前为止,我想出了以下代码:SortedListmList;BlasomeElement=mList[key];Blanext=mList[mList.Keys[mList.IndexOfKey(key)+1]];我不确定这是否是最明智的做法;-) 最佳答案 因为您可以通过index(seetheRemarkssection)访问SortedList,我建议使用以下内容:varindex=mList.IndexOfKey(key);varfirst=mList.Values[index]

c# - ActionResult<IEnumerable<T>> 必须返回一个 List<T>

使用ASP.NETCore2.1获取以下代码:[HttpGet("/unresolved")]publicasyncTask>>GetUnresolvedIdentities(){varresults=await_identities.GetUnresolvedIdentities().ConfigureAwait(false);returnresults.ToList();}自从GetUnresolvedIdentities()我就想到了返回IEnumerable我可以返回returnawait_identities.GetUnresolvedIdentities().Configu

c# - AllowUserToAddRows 不适用于 DataGridView 上的 List<> 数据源

我有一个DataGridView与DataSource设置为List但是,当我设置AllowUserToAddRows时,新行指示器不显示至true,当我设置DataSource至BindingList,这似乎解决了问题。问:应该替换我的List与BindingList或者有更好的解决方案? 最佳答案 是否myClass有一个公共(public)的无参数构造函数?如果不是,您可以从BindingList派生并覆盖AddNewCore调用您的自定义构造函数。(edit)或者-只需将您的列表包装在BindingSource中它可能会起作

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# - 如何使用 Linq to object 构建层次结构?

我有一个数据结构列表:publicListPersonals(){returnnewList{newPersonal{Id=0,Name="Name0"},newPersonal{Id=1,Name="Name1",ParentId=0},newPersonal{Id=2,Name="Name2",ParentId=0},newPersonal{Id=3,Name="Name3",ParentId=0},newPersonal{Id=4,Name="Name4",ParentId=1},newPersonal{Id=5,Name="Name5",ParentId=1},newPerso

c# - 正确公开 List<T>?

我知道我不应该公开List在一个属性中,但我想知道正确的方法是什么?例如,这样做:publicstaticclassClass1{privatereadonlystaticList_list;publicstaticIEnumerableList{get{return_list;//return_list.AsEnumerable();behavesthesame}}staticClass1(){_list=newList();_list.Add("One");_list.Add("Two");_list.Add("Three");}}将允许我的调用者简单地转换回List:privat