如何在c#.net中显示来自arraylist的数据...... [英] how to display a data from arraylist in c# .net......
本文介绍了如何在c#.net中显示来自arraylist的数据......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#.net中显示来自arraylist的数据......
解决方案
此链接可以帮助你
ArrayList [ ^ ]
使用ArrayList [ ^ ]
以下代码示例演示如何创建和初始化 ArrayList [ ^ ]以及如何打印出它的值
使用系统;
我们ing System.Collections;
public class SamplesArrayList {
public static void Main(){
// 创建并初始化一个新的ArrayList。
ArrayList myAL = new ArrayList();
myAL.Add( Hello);
myAL.Add( World);
myAL.Add( !);
// 显示ArrayList的属性和值。
Console.WriteLine( myAL);
Console.WriteLine( Count:{0},myAL.Count);
Console.WriteLine( 容量:{0},myAL.Capacity);
Console.Write( 值:);
PrintValues(myAL);
}
public static void PrintValues(IEnumerable myList){
foreach ( Object obj in myList)
Console.Write( {0},obj);
Console.WriteLine();
}
}
/ *
此代码生成类似于以下内容的输出:
myAL
计数:3
容量:4
值:Hello World!
* /
另请参阅:
如何使用C#ArrayList类 [ ^ ]
你可以试试像
ArrayList arr = new ArrayList();
for ( int iIndex = 0 ; iIndex < arr.Count; iIndex ++)
{
object o = arr [iIndex];
}
但我宁愿一起去
列表类 [ ^ ]和 List.Count Property [ ^ ]
how to display a data from arraylist in c# .net......
解决方案
This link may help you
ArrayList[^]
Use ArrayList[^]
The following code example shows how to create and initialize an ArrayList [^]and how to print out its values"
using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add("Hello"); myAL.Add("World"); myAL.Add("!"); // Displays the properties and values of the ArrayList. Console.WriteLine( "myAL" ); 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 output similar to the following: myAL Count: 3 Capacity: 4 Values: Hello World ! */
Also refer:
How to use C# ArrayList Class[^]
You can try something like
ArrayList arr = new ArrayList(); for (int iIndex = 0; iIndex < arr.Count; iIndex++) { object o = arr[iIndex]; }
But I would rather go with
List Class[^] and List.Count Property[^]
这篇关于如何在c#.net中显示来自arraylist的数据......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文