List物件集合一些擴充套件方法

2022-02-26 05:31:18 字數 1513 閱讀 3183

// 商品集合資訊

listlist = new list()

,new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

// 除了id其它字段重複資料

new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

// 完全重複資料

new product() ,

new product() ,

new product() ,

new product() ,

new product() ,

};//// 1:根據條件篩選**大於3000的商品資訊

//var query = list.where(p=>p.price>3000).tolist();

//foreach (var item in query)

////// 2-1:去除重複的資料(宣告乙個類繼承:iequalitycomparer)

//var query = list.distinct(new distinctcomparer());

//foreach (var item in query.tolist())

////// 2-2:利用hashset去除重複資料

//var js = new list() ;

//hashseths = new hashset(js); //此時已經去掉重複的資料儲存在hashset中

//foreach (var item in hs)

////// 獲取list集合總數

//var query = list.count();

//// 新增資料

product() );

//foreach (var item in list)

// //// 新增資料

list() });

//foreach (var item in list)

////// 刪除所有資料

//var query = list.count();

//// 刪除指定資料

product() );

//foreach (var item in list)

//// foreach 遍歷集合

list.foreach(p =>

{console.writeline(p.id + "--" + p.code + "--" + p.name + "--" + p.price + "--" + p.remark);

list集合中還有許多擴充套件方法。以後持續補充。

Map轉換List一些方法

因為用到了參考了 csdn 大神ricky fung 的一些思路,萬分感謝 map的key與value 轉換成list map map new hashmap map.put 第乙個 first map.put 第二個 two list listkey new arraylist map的key集合...

關於List集合的一些基本操作

宣告需要操作的student類以及要轉換的person類 public class student iformattable,icomparable public string name public double score public student int id,string name,do...

集合相關的一些方法

擴充套件 collections 中獲得list 中最大值的方法過濾掉為null的值 param coll 引數 list param 引數型別 return public static t max collection coll while i.hasnext if next null next....