C#阵列Array排序
五一假期回来,练习一下C#的一些知识,了解一下排序。
练习数据:
int[] ints = { , , , , , , , , };
写一个类:

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;
}
}
}
Source Code
为这个类,添加一个方法,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);
}
}
Source Code
把Array数据copy to ArrayList,还可以使用另外的方法,arrayToArrayListWithAddRange()

public void arrayToArrayListWithAddRange()
{
_al.AddRange(ArrayData);
}
Source Code
为上面的类,写一个ArrayList数据集Sort();

public void Sort()
{
_al.Sort();
}
Source Code
再为类写一个方法,就是输出ArrayList的数据:

public void Output()
{
foreach (int i in _al)
{
Console.WriteLine(i.ToString());
}
}
Source Code
所需要的方法,均写完,在控制台程序使用它们了。

上面#17,#18行代码,可以在类new时,一起传入:

上面#20行代码,由于我们在Bw这个类别中,有写了另外一个方法,所以,也可以这样子:

OK,实现对数据进行排序:

C#阵列Array排序的更多相关文章
- php array 排序 感悟
array 排序总体有这几个函数sort.rsort.asort.arsort.ksort.krsort.usort.uasort.uksort. 一开始我记来记去总是有点混乱,后来认真对比后终于清 ...
- Array排序方法sort()中的大坑
sort() 方法用于对数组的元素进行排序. 但是排序结果就有点坑了,都不按常规出牌的: // 看上去正常的结果: ['Google', 'Apple', 'Microsoft'].sort(); / ...
- [LeetCode] 360. Sort Transformed Array 排序转换后的数组
Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...
- array排序(按数组中对象的属性进行排序)
使用array.sort()对数组中对象的属性进行排序 <template> <div> <a @click="sortArray()">降序& ...
- 【Stackoverflow好问题】java在,如何推断阵列Array是否包括指定的值
问题 java中,怎样推断数组Array是否包括指定的值 精华回答 1. Arrays.asList(...).contains(...) 2. 使用 Apache Commons Lang包中的Ar ...
- leetCode 33.Search in Rotated Sorted Array(排序旋转数组的查找) 解题思路和方法
Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...
- javascript 数组Array排序
var numberAry = [9,9,10,8,7,80,33,55,22]; numberAry.sort(); /*输出:10,22,33,55,7,8,80,9,9 上面的代码没有按照数值的 ...
- ruby 数组array 排序sort 和sort!
1. sort → new_ary click to toggle source sort { |a, b| block } → new_ary Returns a new array created ...
- IOS Array 排序方法
NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) { if ([obj1 integerVal ...
随机推荐
- php soap使用示例
soap_client.php <?php try { $client = new SoapClient( null, array('location' =>"http://lo ...
- Halcon下载、安装
下载地址: 官网:http://www.halcon.com/halcon/download/ Halcon学习网:http://www.ihalcon.com/read.php?tid=56 { 最 ...
- 【docker】学习笔记一:制作自己的centos6.9镜像
前言: 最近开始研究docker,在这里做一个记录. 本来开始想用centos7系列做镜像,毕竟是最新版本的centos,但是centos7有一个严重的bug,就是正常启动的镜像不能使用systemc ...
- Module.exports和exports的区别
原文链接: https://www.ycjcl.cc/2017/02/10/module-exportshe-exportsde-qu-bie/ 学习Seajs时,看到了exports.doSomet ...
- Hadoop- 分布式资源管理YARN架构讲解
YARN是分布式资源管理,每一台机器都要去管理该台计算机的资源,Yarn负责为MapReduce程序分配运算硬件资源.每一台机器的管理者叫 NodeManager,整个集群的管理者管理着整个集群的No ...
- 织梦CMS博客风格模板
织梦CMS博客风格模板,织梦CMS,博客模板,CMS模板.程序模板. 模板地址:http://www.huiyi8.com/sc/7248.html
- linux下MySQL5.6安装记录
MySQL下载地址: ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/http://mirrors.sohu.com/mysql/ ...
- L83
Kids Gulp 7 Trillion Calories Per Year Kids from the ages of 2 to 19, consume about seven trillion c ...
- (转)linux 打开文件数 too many open files 解决方法
too many open files 出现这句提示的原因是程序打开的文件/socket连接数量超过系统设定值. 查看每个用户最大允许打开文件数量 ulimit -a fdipzone@ubuntu: ...
- JQuery添加删除标签
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <script src= ...