ArrayList

 BinarySearch (Object) 方法

使用默认的比较器在整个已排序的 ArrayList 中搜索元素,并返回该元素从零开始的索引。

参数
value
类型: System.Object

要定位的 Object。该值可以为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing

返回值
类型: System.Int32

如果找到 value,则为已排序的 ArrayList 中从零开始的 value 索引;否则为一个负数,它是大于 value 的下一个元素索引的按位求补,如果没有更大的元素,则为 Count 的按位求补。

 

BinarySearch 方法 (Object, IComparer)

 

 

使用指定的比较器在整个已排序的 ArrayList 中搜索元素,并返回该元素从零开始的索引。

参数
value
类型: System.Object

要定位的 Object。该值可以为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing

comparer
类型: System.Collections.IComparer

比较元素时要使用的 IComparer 实现。

- 或 -

nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing 表示使用默认比较器,即每个元素的 IComparable 实现。

返回值
类型: System.Int32

如果找到 value,则为已排序的 ArrayList 中从零开始的 value 索引;否则为一个负数,它是大于 value 的下一个元素索引的按位求补,如果没有更大的元素,则为 Count 的按位求补。

 

BinarySearch 方法 (Int32, Int32, Object, IComparer)

使用指定的比较器在已排序 ArrayList 的某个元素范围中搜索元素,并返回该元素从零开始的索引。

参数
index
类型: System.Int32

要搜索的范围从零开始的起始索引。

count
类型: System.Int32

要搜索的范围的长度。

value
类型: System.Object

要定位的 Object。该值可以为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing

comparer
类型: System.Collections.IComparer

比较元素时要使用的 IComparer 实现。

- 或 -

nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing 表示使用默认比较器,即每个元素的 IComparable 实现。

返回值
类型: System.Int32

如果找到 value,则为已排序的 ArrayList 中从零开始的 value 索引;否则为一个负数,它是大于 value 的下一个元素索引的按位求补,如果没有更大的元素,则为 Count 的按位求补。

C#
using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {

      // Creates and initializes a new ArrayList. BinarySearch requires
      // a sorted ArrayList.
      ArrayList myAL = new ArrayList();
      for ( int i = 0; i <= 4; i++ )
         myAL.Add( i*2 );

      // Displays the ArrayList.
      Console.WriteLine( "The Int32 ArrayList contains the following:" );
      PrintValues( myAL );

      // Locates a specific object that does not exist in the ArrayList.
      Object myObjectOdd = 3;
      FindMyObject( myAL, myObjectOdd );

      // Locates an object that exists in the ArrayList.
      Object myObjectEven = 6;
      FindMyObject( myAL, myObjectEven );
   }

   public static void FindMyObject( ArrayList myList, Object myObject )  {
      int myIndex=myList.BinarySearch( myObject );
      if ( myIndex < 0 )
         Console.WriteLine( "The object to search for ({0}) is not found. The next larger object is at index {1}.", myObject, ~myIndex );
      else
         Console.WriteLine( "The object to search for ({0}) is at index {1}.", myObject, myIndex );
   }

   public static void PrintValues( IEnumerable myList )  {
      foreach ( Object obj in myList )
         Console.Write( "   {0}", obj );
      Console.WriteLine();
   }

}
/* 
This code produces the following output.

The Int32 ArrayList contains the following:
   0   2   4   6   8
The object to search for (3) is not found. The next larger object is at index 2.
The object to search for (6) is at index 3.
*/ 
CopyTo 方法 (Int32, Array, Int32, Int32)
从目标数组的指定索引处开始,将一定范围的元素从 ArrayList 复制到兼容的一维 Array
  
  
参数 index
类型: System.Int32

ArrayList 中复制开始位置的从零开始的索引。

array
类型: System.Array

作为从 ArrayList 复制的元素的目标位置的一维 ArrayArray 必须具有从零开始的索引。

arrayIndex
类型: System.Int32

array 中从零开始的索引,在此处开始复制。

count
类型: System.Int32

要复制的元素数。

using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {

      // Creates and initializes the source ArrayList.
      ArrayList mySourceList = new ArrayList();
      mySourceList.Add( "three" );
      mySourceList.Add( "napping" );
      mySourceList.Add( "cats" );
      mySourceList.Add( "in" );
      mySourceList.Add( "the" );
      mySourceList.Add( "barn" );

      // Creates and initializes the one-dimensional target Array.
      String[] myTargetArray = new String[15];
      myTargetArray[0] = "The";
      myTargetArray[1] = "quick";
      myTargetArray[2] = "brown";
      myTargetArray[3] = "fox";
      myTargetArray[4] = "jumped";
      myTargetArray[5] = "over";
      myTargetArray[6] = "the";
      myTargetArray[7] = "lazy";
      myTargetArray[8] = "dog";

      // Displays the values of the target Array.
      Console.WriteLine( "The target Array contains the following (before and after copying):" );
      PrintValues( myTargetArray, ' ' );

      // Copies the second element from the source ArrayList to the target Array, starting at index 7.
      mySourceList.CopyTo( 1, myTargetArray, 7, 1 );

      // Displays the values of the target Array.
      PrintValues( myTargetArray, ' ' );

      // Copies the entire source ArrayList to the target Array, starting at index 6.
      mySourceList.CopyTo( myTargetArray, 6 );

      // Displays the values of the target Array.
      PrintValues( myTargetArray, ' ' );

      // Copies the entire source ArrayList to the target Array, starting at index 0.
      mySourceList.CopyTo( myTargetArray );

      // Displays the values of the target Array.
      PrintValues( myTargetArray, ' ' );

   }

   public static void PrintValues( String[] myArr, char mySeparator )  {
      for ( int i = 0; i < myArr.Length; i++ )
         Console.Write( "{0}{1}", mySeparator, myArr[i] );
      Console.WriteLine();
   }

}


/*
This code produces the following output.

The target Array contains the following (before and after copying):
The quick brown fox jumped over the lazy dog
The quick brown fox jumped over the napping dog
The quick brown fox jumped over three napping cats in the barn
three napping cats in the barn three napping cats in the barn

*/

 

GetEnumerator 方法

 

返回整个 ArrayList 的一个枚举数 // Example for the String.GetEnumerator( ) method.   
using System;   
using System.Collections;   
  
class GetEnumerator    
{   
    
public static void Main()    
    
{   
        Console.WriteLine(    
            
"This example of String.GetEnumerator( ) " +   
            
"generates the following output." );   
  
        EnumerateAndDisplay( 
"Test Case" );   
        EnumerateAndDisplay( 
"Has/ttwo/ttabs" );   
        EnumerateAndDisplay( 
"Two/nnew/nlines" );   
    }
   
  
    
static void EnumerateAndDisplay( String Operand )   
    
{   
        Console.WriteLine(    
            
"/nThe characters in the string /"{0}/" are:",   
            Operand );   
  
        IEnumerator OperandEnum 
= Operand.GetEnumerator( );   
        
int         CharCount = 0;   
  
        
while( OperandEnum.MoveNext( ) )   
        
{   
            CharCount
++;   
            Console.Write( 
" '{0}' ", OperandEnum.Current );   
        }
   
        Console.WriteLine( 
"/n Character count: {0}", CharCount );   
    }
   
}
   
  
/*  
This example of String.GetEnumerator( ) generates the following output.  
 
The characters in the string "Test Case" are:  
 'T'  'e'  's'  't'  ' '  'C'  'a'  's'  'e'  
 Character count: 9  
 
The characters in the string "Has       two     tabs" are:  
 'H'  'a'  's'  '       '  't'  'w'  'o'  '     '  't'  'a'  'b'  's'  
 Character count: 12  
 
The characters in the string "Two  
new  
lines" are:  
 'T'  'w'  'o'  '  
'  'n'  'e'  'w'  '  
'  'l'  'i'  'n'  'e'  's'  
 Character count: 13  


GetRange 方法
参数
index
类型: System.Int32

范围开始处的从零开始的 ArrayList 索引。

count
类型: System.Int32

范围中的元素数。

返回值
类型: System.Collections.ArrayList

ArrayList,它表示源 ArrayList 中元素的子集。

 

using System;
using System.Collections;
public class SamplesArrayList  {

   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( "jumped" );
      myAL.Add( "over" );
      myAL.Add( "the" );
      myAL.Add( "lazy" );
      myAL.Add( "dog" );

      // Creates and initializes the source ICollection.
      Queue mySourceList = new Queue();
      mySourceList.Enqueue( "big" );
      mySourceList.Enqueue( "gray" );
      mySourceList.Enqueue( "wolf" );

      // Displays the values of five elements starting at index 0.
      ArrayList mySubAL = myAL.GetRange( 0, 5 );
      Console.WriteLine( "Index 0 through 4 contains:" );
      PrintValues( mySubAL, '/t' );

      // Replaces the values of five elements starting at index 1 with the values in the ICollection.
      myAL.SetRange( 1, mySourceList );

      // Displays the values of five elements starting at index 0.
      mySubAL = myAL.GetRange( 0, 5 );
      Console.WriteLine( "Index 0 through 4 now contains:" );
      PrintValues( mySubAL, '/t' );

   }

   public static void PrintValues( IEnumerable myList, char mySeparator )  {
      foreach ( Object obj in myList )
         Console.Write( "{0}{1}", mySeparator, obj );
      Console.WriteLine();
   }

}


/* 
This code produces the following output.

Index 0 through 4 contains:
        The     quick   brown   fox     jumped
Index 0 through 4 now contains:
        The     big     gray    wolf    jumped
*/ 

Repeat 方法 
返回 ArrayList,它的元素是指定值的副本。
      
      
参数
value
类型: System.Object

要在新 ArrayList 中对其进行多次复制的 Object。该值可以为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing

count
类型: System.Int32

value 应被复制的次数。

返回值

具有 count 所指定的元素数的 ArrayList,其中的所有元素都是 value 的副本。

 

using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates a new ArrayList with five elements and initialize each element with a null value. ArrayList myAL = ArrayList.Repeat( null, 5 ); // Displays the count, capacity and values of the ArrayList. Console.WriteLine( "ArrayList with five elements with a null value" ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // Creates a new ArrayList with seven elements and initialize each element with the string "abc". myAL = ArrayList.Repeat( "abc", 7 ); // Displays the count, capacity and values of the ArrayList. Console.WriteLine( "ArrayList with seven elements with a string value" ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { foreach ( Object obj in myList ) Console.Write( " {0}", obj ); Console.WriteLine(); } } /* This code produces the following output. ArrayList with five elements with a null value Count : 5 Capacity : 16 Values: ArrayList with seven elements with a string value Count : 7 Capacity : 16 Values: abc abc abc abc abc abc abc */

 

 

Sort 方法 (IComparer)

使用指定的比较器对整个 ArrayList 中的元素进行排序。

参数
comparer
类型: System.Collections.IComparer

比较元素时要使用的 IComparer 实现。

- 或 -

若为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing,则使用每个元素的 IComparable 实现。

 

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 */

 

ToArray 方法 (Type)

ArrayList 的元素复制到指定元素类型的新数组中。

参数
type
类型: System.Type

要创建并向其复制元素的目标数组的元素 Type

返回值
类型: System.Array

指定元素类型的数组,它包含 ArrayList 中元素的副本。

 

using System; using System.Collections; public class SamplesArrayList { 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( "jumped" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); // Displays the values of the ArrayList. Console.WriteLine( "The ArrayList contains the following values:" ); PrintIndexAndValues( myAL ); // Copies the elements of the ArrayList to a string array. String[] myArr = (String[]) myAL.ToArray( typeof( string ) ); // Displays the contents of the string array. Console.WriteLine( "The string array contains the following values:" ); PrintIndexAndValues( myArr ); } public static void PrintIndexAndValues( ArrayList myList ) { int i = 0; foreach ( Object o in myList ) Console.WriteLine( "/t[{0}]:/t{1}", i++, o ); Console.WriteLine(); } public static void PrintIndexAndValues( String[] myArr ) { for ( int i = 0; i < myArr.Length; i++ ) Console.WriteLine( "/t[{0}]:/t{1}", i, myArr[i] ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList contains the following values: [0]: The [1]: quick [2]: brown [3]: fox [4]: jumped [5]: over [6]: the [7]: lazy [8]: dog The string array contains the following values: [0]: The [1]: quick [2]: brown [3]: fox [4]: jumped [5]: over [6]: the [7]: lazy [8]: dog */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
城市应急指挥系统是智慧城市建设的重要组成部分,旨在提高城市对突发事件的预防和处置能力。系统背景源于自然灾害和事故灾难频发,如汶川地震和日本大地震等,这些事件造成了巨大的人员伤亡和财产损失。随着城市化进程的加快,应急信息化建设面临信息资源分散、管理标准不统一等问题,需要通过统筹管理和技术创新来解决。 系统的设计思路是通过先进的技术手段,如物联网、射频识别、卫星定位等,构建一个具有强大信息感知和通信能力的网络和平台。这将促进不同部门和层次之间的信息共享、交流和整合,提高城市资源的利用效率,满足城市对各种信息的获取和使用需求。在“十二五”期间,应急信息化工作将依托这些技术,实现动态监控、风险管理、预警以及统一指挥调度。 应急指挥系统的建设目标是实现快速有效的应对各种突发事件,保障人民生命财产安全,减少社会危害和经济损失。系统将包括预测预警、模拟演练、辅助决策、态势分析等功能,以及应急值守、预案管理、GIS应用等基本应用。此外,还包括支撑平台的建设,如接警中心、视频会议、统一通信等基础设施。 系统的实施将涉及到应急网络建设、应急指挥、视频监控、卫星通信等多个方面。通过高度集成的系统,建立统一的信息接收和处理平台,实现多渠道接入和融合指挥调度。此外,还包括应急指挥中心基础平台建设、固定和移动应急指挥通信系统建设,以及应急队伍建设,确保能够迅速响应并有效处置各类突发事件。 项目的意义在于,它不仅是提升灾害监测预报水平和预警能力的重要科技支撑,也是实现预防和减轻重大灾害和事故损失的关键。通过实施城市应急指挥系统,可以加强社会管理和公共服务,构建和谐社会,为打造平安城市提供坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值