通過寫乙個Demo展示C 中多種常用的集合排序方法

2021-07-30 08:28:12 字數 1447 閱讀 9738

不多說,程式很簡單,就是將集合中的資料進行排序,但使用到的知識點還是比較多的,大牛勿噴,謹獻給初學者!直接上程式吧!

namespace

demo

console.writeline(

"---------------------------");

//2、使用繼承icomparer介面的函式來進行排序

list.sort(new

productcomparet());

foreach (product product in

list)

console.writeline(

"---------------------------");

//3、使用委託來進行排序

list.sort(delegate

(product x, product y)

);foreach (product product in

list)

//4、使用lambda表示式來進行排序;

list.sort((x, y) =>x.price.compareto(y.price));

foreach (product product in

list)

//5、使用擴充套件方法來進行排序

foreach (product product in list.orderby(p=>p.price))

console.readkey();}}

public

class

product

public

decimal price

public

static

arraylist getarraylist()

,new product ,

new product };}

public

static listgetlist()

,new product ,

new product };}

public

override

string

tostring()

--", name, price);}}

//////

使用icomparer對arraylist進行排序

///顯示實現compare介面,常用arraylist型別的集合來呼叫

/// public

class

productcompare : icomparer

else}}

//////

使用icomparer

進行排序

///顯式實現compare介面,常用list

型別的集合來呼叫

/// public

class productcomparet : icomparer

else}}

}

通過乙個demo了解Redux

todolist小demo 效果展示 專案位址 回到頂部 單向 資料流 資料流是我們的行為與響應的抽象 使用資料流能幫我們明確了行為對應的響應,這和react的狀態可 的思想是不謀而合的。常見的資料流框架有flux reflux redux。相比其它資料流框架,redux輕量 壓縮後只有2k 而且在...

通過乙個demo了解Redux

todolist小demo 效果展示 專案位址 單向 資料流 資料流是我們的行為與響應的抽象 使用資料流能幫我們明確了行為對應的響應,這和react的狀態可 的思想是不謀而合的。常見的資料流框架有flux reflux redux。相比其它資料流框架,redux輕量 壓縮後只有2k 而且在乙個rea...

通過乙個demo了解Redux

todolist小demo 效果展示 專案位址 單向 資料流 資料流是我們的行為與響應的抽象 使用資料流能幫我們明確了行為對應的響應,這和react的狀態可 的思想是不謀而合的。常見的資料流框架有flux reflux redux。相比其它資料流框架,redux輕量 壓縮後只有2k 而且在乙個rea...