请教:C#里有象Delphi里的TObjectList这样的类吗?(80分)

  • 主题发起人 主题发起人 hycstudio
  • 开始时间 开始时间
H

hycstudio

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:C#里有象Delphi里的TObjectList这样的类吗?
如果有,大概是怎么用的?
大家可怜可怜,我没有分了!谢谢!
 
有ArrayList就跟delphi里的list差不多.
ArrayList.add 添加
ArrayList.item 取出Object.
.....
具体请看MSDN,中文,说的很清楚.
 
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" );
// Creates and initializes a new Queue.
Queue myQueue = new Queue();
myQueue.Enqueue( "jumped" );
myQueue.Enqueue( "over" );
myQueue.Enqueue( "the" );
myQueue.Enqueue( "lazy" );
myQueue.Enqueue( "dog" );
// Displays the ArrayList and the Queue.
Console.WriteLine( "The ArrayList initially contains the following:" );
PrintValues( myAL, '/t' );
Console.WriteLine( "The Queue initially contains the following:" );
PrintValues( myQueue, '/t' );
// Copies the Queue elements to the end of the ArrayList.
myAL.AddRange( myQueue );
// Displays the ArrayList.
Console.WriteLine( "The ArrayList now contains the following:" );
PrintValues( myAL, '/t' );
}
public static void PrintValues( IEnumerable myList, char mySeparator ) {
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "{0}{1}", mySeparator, myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.
The ArrayList initially contains the following:
The quick brown fox
The Queue initially contains the following:
jumped over the lazy do
g
The ArrayList now contains the following:
The quick brown fox jumped over the lazy do
g
*/
是这段代码吧!我觉得就和数组没有什么差别。
 
后退
顶部