百合花幼儿园,javaswing,翠蓝眼蛱蝶
五一假期回来,练习一下c#的一些知识,了解一下排序。
练习数据:
int[] ints = { 16, 75, 1, 39, 22, 43, 3, 68, 55 };
写一个类:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapplicationdemo { public class bw { public int[] arraydata { get; set; } public bw() { } public bw(int[] myarraydata) { this.arraydata = myarraydata; } } }
为这个类,添加一个方法,arraytoarraylistwithforeach() 即是使用foreach方法,把array数据copy to arraylist数据集:
system.collections.arraylist _al = new system.collections.arraylist(); public void arraytoarraylistwithforeach() { foreach (int i in arraydata) { _al.add(i); } }
把array数据copy to arraylist,还可以使用另外的方法,arraytoarraylistwithaddrange()
public void arraytoarraylistwithaddrange() { _al.addrange(arraydata); }
为上面的类,写一个arraylist数据集sort();
public void sort() { _al.sort(); }
再为类写一个方法,就是输出arraylist的数据:
public void output() { foreach (int i in _al) { console.writeline(i.tostring()); } }
所需要的方法,均写完,在控制台程序使用它们了。
上面#17,#18行代码,可以在类new时,一起传入:
上面#20行代码,由于我们在bw这个类别中,有写了另外一个方法,所以,也可以这样子:
ok,实现对数据进行排序:
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论