五一假期回来,练习一下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排序的更多相关文章

  1. php array 排序 感悟

    array  排序总体有这几个函数sort.rsort.asort.arsort.ksort.krsort.usort.uasort.uksort. 一开始我记来记去总是有点混乱,后来认真对比后终于清 ...

  2. Array排序方法sort()中的大坑

    sort() 方法用于对数组的元素进行排序. 但是排序结果就有点坑了,都不按常规出牌的: // 看上去正常的结果: ['Google', 'Apple', 'Microsoft'].sort(); / ...

  3. [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( ...

  4. array排序(按数组中对象的属性进行排序)

    使用array.sort()对数组中对象的属性进行排序 <template> <div> <a @click="sortArray()">降序& ...

  5. 【Stackoverflow好问题】java在,如何推断阵列Array是否包括指定的值

    问题 java中,怎样推断数组Array是否包括指定的值 精华回答 1. Arrays.asList(...).contains(...) 2. 使用 Apache Commons Lang包中的Ar ...

  6. 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 ...

  7. javascript 数组Array排序

    var numberAry = [9,9,10,8,7,80,33,55,22]; numberAry.sort(); /*输出:10,22,33,55,7,8,80,9,9 上面的代码没有按照数值的 ...

  8. ruby 数组array 排序sort 和sort!

    1. sort → new_ary click to toggle source sort { |a, b| block } → new_ary Returns a new array created ...

  9. IOS Array 排序方法

    NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) { if ([obj1 integerVal ...

随机推荐

  1. 性能测试--Jmeter之wordpress示例

    Jmeter之wordpress示例 WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站.也可以把 WordPress当作一个内容管理 ...

  2. iOS app submission : missing 64-bit support

  3. 7-3 堆栈模拟队列(25 point(s)) 【数据结构】

    7-3 堆栈模拟队列(25 point(s)) 设已知有两个堆栈S1和S2,请用这两个堆栈模拟出一个队列Q. 所谓用堆栈模拟队列,实际上就是通过调用堆栈的下列操作函数: int IsFull(Stac ...

  4. 【Leetcode-easy】Remove Nth Node From End of List

    思路1:设置两个指针p1,p2指向表头,p1先走n步.再两个指针同时走.当p1指针指到链表尾部时,P2指针已经在需要删除节点的前一位.一定要注意一些细节. class ListNode { int v ...

  5. 使用vscode写typescript(node.js环境)起手式

    动机 一直想把typescript在服务端开发中用起来,主要原因有: javascript很灵活,但记忆力不好的话,的确会让你头疼,看着一月前自己写的代码,一脸茫然. 类型检查有利有敝,但在团队开发中 ...

  6. elementaryos必装软件

    所使用版本:elementaryos-0.4-stable-amd64.20160909.iso vmtools jdk sougouinput IntellijIEAD

  7. html5--2.3新的布局元素(2)-article

    html5--2.3新的布局元素(2)-article 学习要点 了解article元素的语义和用法 完成一个简单的实例 article元素(标签) 用于定义一个独立的内容区块,比如一篇文章,一篇博客 ...

  8. NOIP 2014【斗地主】

    这真是道大火题. 因为保证数据随机,所以开始很多人直接用搜索 + 贪心水过去了,后来,为了遏制骗分这种不良风气的传播,各大 OJ 相继推出了斗地主加强版-- 正解: 先爆搜顺子,枚举打或不打,打多少张 ...

  9. (转)MongoDB和Redis区别

    简介 MongoDB更类似Mysql,支持字段索引.游标操作,其优势在于查询功能比较强大,擅长查询JSON数据,能存储海量数据,但是不支持事务. Mysql在大数据量时效率显著下降,MongoDB更多 ...

  10. codeforces 566D D. Restructuring Company(并查集)

    题目链接: D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes inp ...