草庐IT

set-key-partition-list

全部标签

c# - List.Insert 有任何性能损失吗?

给定一个列表:ListSomeList=newList();正在做:SomeList.Insert(i,val);对比SomeList.Add(val);有任何性能损失吗?如果是,如何取决于:-i-插入索引-SomeList.Count-列表的大小 最佳答案 TheListclassisthegenericequivalentoftheArrayListclass.ItimplementstheIListgenericinterfaceusinganarraywhosesizeisdynamicallyincreasedasrequ

c# - 将 Datagrid.SelectedItems 集合转换到 List<T>

我有这样的课publicclassFoo{publicstringprop1{get;set;}publicstringprop2{get;set;}}还有一个带有List的View模型,此列表用作Bind一个DataGrid,然后在代码隐藏中我需要获取Datagrid.SelectedItems收集并将其转换为List我尝试过的事情:ListSelectedItemsList=(List)DataGrid.SelectedItems;//ORobjectp=DataGrid.SelectedItems;ListSelectedItemsList=((IList)p).Cast().T

C#:将同一个对象添加到两个List<object>变量时,是否在进程中克隆了对象?

我有类似的东西://Declarations:Listlist1=newList();Listlist2=newList();...SomeTypesomething=newSomeType("SomeName");list1.Add(something);list2.Add(something);...list1[indexOfSomething]=newSomeType("SomeOtherName");并且list2中的对象没有改变......这是预期的结果吗? 最佳答案 是的,但没有任何克隆。在分配之前,同一个对象在两个列表

c# - 为从 List<string> 继承的集合实现 GetEnumerator()

我正在尝试实现FilePathCollection。它的项目将是简单的文件名(没有路径-例如“image.jpg”)。通过foreach循环使用集合后,它应该返回通过与baseDirectory连接创建的完整路径。我怎样才能做到这一点?publicclassFilePathCollection:List{stringbaseDirectory;publicFilePathCollection(stringbaseDirectory){this.baseDirectory=baseDirectory;}newpublicSystem.Collections.IEnumeratorGetE

c# - 如何为数组数据成员定义 get 和 set?

我正在创建一个类Customer,它具有以下数据成员和属性:privatestringcustomerName;privatedouble[]totalPurchasesLastThreeDays;//arrayof3elementsthatwillholdthetotalsofhowmuchthecustomerpurchasedforthepastthreedaysi.e.element[0]=100,element[1]=50,element[2]=250publicstringCustomerName{get{returncustomerName;}set{customerNa

c# - System.StackOverflowException ,何时使用 get set 属性?

在wcfserviceLibrary.DLL中发生类型为“System.StackOverflowException”的未处理异常代码如下。[DataContract]publicclassmemberdesignations{[DataMember]publicstringDesigId{get{returnDesigId;}set{DesigId=value;}}[DataMember]publicstringDesignationName{get{returnDesignationName;}set{DesignationName=value;}}}然后我有如下的Typememb

c# - List<long> 在 C# 中以逗号分隔的字符串

这经常出现。我有一个列表,我想转到列表中所有元素的逗号分隔字符串,我可以在SQL中使用它。在C#中执行此操作的最优雅方法是什么?迭代所有这些都很好,除了第一个或最后一个元素必须是特殊大小写,因为我不想要前导或尾随逗号。有好的单线吗? 最佳答案 string.Join是你的friend...varlist=newList{1,2,3,4};varcommaSeparated=string.Join(",",list); 关于c#-List在C#中以逗号分隔的字符串,我们在StackOver

c# - 遍历强类型泛型 List<T> 的最佳方法是什么?

在C#.NET和VB.NET中循环访问强类型泛型列表的最佳方法是什么? 最佳答案 对于C#:foreach(ObjectTypeobjectIteminobjectTypeList){//...dosomestuff}PurpleAnt对VB.NET的回答:ForEachobjectItemasObjectTypeinobjectTypeList'Dosomestuff'Next 关于c#-遍历强类型泛型List的最佳方法是什么?,我们在StackOverflow上找到一个类似的问题:

c# - 检查 List<Int32> 值是否连续

ListdansConList=newList();dansConList[0]=1;dansConList[1]=2;dansConList[2]=3;ListdansRandomList=newList();dansRandomList[0]=1;dansRandomList[1]=2;dansRandomList[2]=4;我需要一个方法,在评估上述列表时,将返回false对于dansRandomList和true对于dansConList基于事实dansConList在它的值中有一个连续的数字序列,而dansRandomList没有(缺少值3)。如果可能,最好使用LINQ。我尝

c# - 将 set 访问器添加到类中的属性,该类派生自只有一个 get 访问器的抽象类

我有一个抽象类,AbsClass实现一个接口(interface),IClass.IClass有几个属性只有Get访问器。AbsClass实现的属性IClass作为要在派生自的类中定义的抽象属性AbsClass.所以所有派生自的类AbsClass还需要满足IClass通过与Get访问器具有相同的属性。但是,在某些情况下,我希望能够向来自的属性添加set访问器。IClass.然而,如果我尝试覆盖中的抽象属性AbsClass使用setaccessor我收到此错误ConcClassA.Bottom.Set无法覆盖,因为AbsClass.Bottom没有可覆盖的set访问器见ConcClass