C#中如何动态设置一个数组的长度? C#中如何动态设置一个数组的长度?下列这种定义方式是否正确:int i = 3 ;byte[] b = new byte[ i ] ;??????????????????????????????????????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以用动态数组呀arraylist b=new arraylist(); Array 类好像还有一个CreateInstance吧~ ArrayList 的容量是该列表可包含的元素数。随着向 ArrayList 中添加元素,容量通过重新分配按需自动增加。可通过调用 TrimToSize 或通过显式设置 Capacity 属性来减少容量。此集合中的索引从零开始。ArrayList 接受空引用(Visual Basic 中为 Nothing)作为有效值并且允许重复的元素。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( "\tCount: {0}", myAL.Count ); Console.WriteLine( "\tCapacity: {0}", myAL.Capacity ); Console.Write( "\tValues:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current ); Console.WriteLine(); }}/* This code produces the following output.myAL Count: 3 Capacity: 16 Values: Hello World !*/ ArrayList 最适合了!象楼住的定义方式,肯定是错的 ArrayList al=new ArrayList (); al.Add (5); al.Add (6); for(int i=0;i<al.Count ;i++) MessageBox.Show (al[i].ToString ());//结果:56 dsoframer.ocx控件如何才能在客户端自动注册 TCP服务端多客户端连接时产生的问题,急~~ 添加控件事件处理程序 在WORD中插入段落并控制样式的问题 文件上传时如何显示进度条???多个文件的。 datagrid表头如何显示中文 怎么在水晶报表中显示ACCESS中的图片!急急急急急急急 关于使用Socket开发C/S程序 用c# 怎么实现winsock重连接! 各位能谈谈学习c#的感受吗 我需要在网络中用一个连接按顺序传送多段字节块,在传送每一个字节块后等待对方的确认,在C#.Net/socket中我该如何做? zglxh3(noproblem):接分!
arraylist b=new 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("Hello");
myAL.Add("World");
myAL.Add("!"); // Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( "\tCount: {0}", myAL.Count );
Console.WriteLine( "\tCapacity: {0}", myAL.Capacity );
Console.Write( "\tValues:" );
PrintValues( myAL );
} public static void PrintValues( IEnumerable myList ) {
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.myAL
Count: 3
Capacity: 16
Values: Hello World !
*/
象楼住的定义方式,肯定是错的
al.Add (5);
al.Add (6);
for(int i=0;i<al.Count ;i++)
MessageBox.Show (al[i].ToString ());//结果:
5
6