欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

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

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

本文實例講述了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)讀取DataSet數(shù)據(jù)并顯示在ListView控件中的方法

欄    目:C#教程

下一篇:C#創(chuàng)建不規(guī)則窗體的4種方式詳解

本文標題:C#中Arraylist的sort函數(shù)用法實例分析

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6912.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有