亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#中Arraylist的sort函數(shù)用法實例分析

 更新時間:2015年10月13日 15:23:19   作者:dongfengkuayue  
這篇文章主要介紹了C#中Arraylist的sort函數(shù)用法,較為詳細的分析了ArrayList的sort函數(shù)的功能、定義及具體使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C#中Arraylist的sort函數(shù)用法。分享給大家供大家參考。具體如下:

ArrayList的sort函數(shù)有幾種比較常用的重載:

1.不帶參數(shù)

2.帶一個參數(shù)

public virtual void Sort(
  IComparer comparer
)

參數(shù)

comparer

類型:System.Collections.IComparer

比較元素時要使用的 IComparer 實現(xiàn)。

- 或 -

null 引用(Visual Basic 中為 Nothing)將使用每個元數(shù)的 IComparable 實現(xiàn)。

示例:

using System;
using System.Collections;
public class SamplesArrayList {
  public class myReverserClass : IComparer {
   // Calls CaseInsensitiveComparer.Compare with the parameters reversed.
   int IComparer.Compare( Object x, Object y ) {
     return( (new CaseInsensitiveComparer()).Compare( y, x ) );
   }
  }
  public static void Main() {
   // Creates and initializes a new ArrayList.
   ArrayList myAL = new ArrayList();
   myAL.Add( "The" );
   myAL.Add( "quick" );
   myAL.Add( "brown" );
   myAL.Add( "fox" );
   myAL.Add( "jumps" );
   myAL.Add( "over" );
   myAL.Add( "the" );
   myAL.Add( "lazy" );
   myAL.Add( "dog" );
   // Displays the values of the ArrayList.
   Console.WriteLine( "The ArrayList initially contains the following values:" );
   PrintIndexAndValues( myAL );
   // Sorts the values of the ArrayList using the default comparer.
   myAL.Sort();
   Console.WriteLine( "After sorting with the default comparer:" );
   PrintIndexAndValues( myAL );
   // Sorts the values of the ArrayList using the reverse case-insensitive comparer.
   IComparer myComparer = new myReverserClass();
   myAL.Sort( myComparer );
   Console.WriteLine( "After sorting with the reverse case-insensitive comparer:" );
   PrintIndexAndValues( myAL );
  }
  public static void PrintIndexAndValues( IEnumerable myList ) {
   int i = 0;
   foreach ( Object obj in myList )
     Console.WriteLine( "\t[{0}]:\t{1}", i++, obj );
   Console.WriteLine();
  }
}
/* 
This code produces the following output.
The ArrayList initially contains the following values:
    [0]:  The
    [1]:  quick
    [2]:  brown
    [3]:  fox
    [4]:  jumps
    [5]:  over
    [6]:  the
    [7]:  lazy
    [8]:  dog
After sorting with the default comparer:
    [0]:  brown
    [1]:  dog
    [2]:  fox
    [3]:  jumps
    [4]:  lazy
    [5]:  over
    [6]:  quick
    [7]:  the
    [8]:  The
After sorting with the reverse case-insensitive comparer:
    [0]:  the
    [1]:  The
    [2]:  quick
    [3]:  over
    [4]:  lazy
    [5]:  jumps
    [6]:  fox
    [7]:  dog
    [8]:  brown 
*/

希望本文所述對大家的C#程序設計有所幫助。

相關文章

  • C#實現(xiàn)計算器功能

    C#實現(xiàn)計算器功能

    這篇文章主要為大家詳細介紹了C#實現(xiàn)計算器功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • 基于C#?實現(xiàn)劉謙春晚魔術(示例代碼)

    基于C#?實現(xiàn)劉謙春晚魔術(示例代碼)

    劉謙春晚魔術是一個讓人嘆為觀止的魔術表演,其中涉及到了數(shù)學、編程和創(chuàng)意的結合,看了春晚魔術的朋友們,是不是好奇春晚劉謙的魔術是怎么變的,本文分享C#?實現(xiàn)劉謙春晚魔術示例代碼,一起看看吧
    2024-02-02
  • 詳解C#批量插入數(shù)據(jù)到Sqlserver中的四種方式

    詳解C#批量插入數(shù)據(jù)到Sqlserver中的四種方式

    本文主要講解一下在Sqlserver中批量插入數(shù)據(jù)。文中大數(shù)據(jù)批量插入方式一和方式四盡量避免使用,而方式二和方式三都是非常高效的批量插入數(shù)據(jù)方式,需要的朋友可以看下
    2016-12-12
  • C#使用HtmlAgilityPack實現(xiàn)解析提取HTML內容

    C#使用HtmlAgilityPack實現(xiàn)解析提取HTML內容

    HtmlAgilityPack是一個HTML解析類庫,這篇文章主要為大家詳細介紹了C#如何使用HtmlAgilityPack實現(xiàn)解析提取HTML內容,感興趣的小伙伴可以參考一下
    2023-12-12
  • C# 命名空間(Namespace)相關知識總結

    C# 命名空間(Namespace)相關知識總結

    這篇文章主要介紹了C# 命名空間(Namespace)的相關知識,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以參考下
    2020-06-06
  • C#實現(xiàn)簡單的飛行棋小游戲

    C#實現(xiàn)簡單的飛行棋小游戲

    這篇文章主要為大家詳細介紹了C#實現(xiàn)簡單的飛行棋小游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下<BR>
    2021-11-11
  • C#采用OpenXml實現(xiàn)給word文檔添加文字

    C#采用OpenXml實現(xiàn)給word文檔添加文字

    這篇文章主要介紹了C#采用OpenXml實現(xiàn)給word文檔添加文字的方法,包括了用法的實例分析,是非常實用的技巧,需要的朋友可以參考下
    2014-09-09
  • 深入理解C# 裝箱和拆箱(整理篇)

    深入理解C# 裝箱和拆箱(整理篇)

    通過裝箱和拆箱操作,能夠在值類型和引用類型中架起一做橋梁.換言之,可以輕松的實現(xiàn)值類型與引用類型的互相轉換
    2017-08-08
  • C#方法中參數(shù)ref和out詳解

    C#方法中參數(shù)ref和out詳解

    這篇文章主要為大家詳細介紹了C#方法中參數(shù)ref和out的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • C# 常用協(xié)議實現(xiàn)模版及FixedSizeReceiveFilter示例(SuperSocket入門)

    C# 常用協(xié)議實現(xiàn)模版及FixedSizeReceiveFilter示例(SuperSocket入門)

    本文主要介紹了常用協(xié)議實現(xiàn)模版及FixedSizeReceiveFilter示例。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-01-01

最新評論