C#中怎样声明一个动态增加的数组呢?????? string[,] cltext = new string[1000,3];我是这样声明的!但我想要数组自动增加大小,而不是我指定它的大小?????应该怎样声明呢????请教各位高手了!谢谢!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用ArrayList类,你可以随意增加元素,它自动适应地变化长度和扩展空间 ArrayList al=new ArrayList(); al.Add("a"); al.Add(1); al.Add(true); string[] a = new string[5]; string[] b = new string[a.Length]; a.CopyTo(b,0); a =new string[10]; b.CopyTo(a,0); 回复人: LGame(JGame) ( ) 信誉:100 2006-02-17 10:22:00 得分: 0 string[] a = new string[5]; string[] b = new string[a.Length]; a.CopyTo(b,0); a =new string[10]; b.CopyTo(a,0); -------------------------------------------------------速度比ArrayList快,因为少了inbox和outBox的时间 给你作个小例子;using System;using System.Collections;namespace ConsoleApplication1{ class Class1 { [STAThread] static void Main(string[] args) { ArrayList[] cltext1=new ArrayList[3]; cltext1[0].Add("a"); //用同样的方式加; } } } 给你一个小例子,但愿对你有帮助。public static Array Redim(Array origArray,Int32 desiredSize) { Type t = origArray.GetType().GetElementType(); Array newArray = Array.CreateInstance(t,desiredSize); Array.Copy(origArray,0,newArray,0,Math.Min(origArray.Length,desiredSize)); return newArray; } public void ArrayReDim() { int[] intAry = new int[0]; intAry = (int[])Redim(intAry,3); intAry[0] = 1; intAry[1] = 2; intAry[2] = 3; } 都什么年代了,还用ArrayList,还拷贝?List<T>是你最明智的选择 我也用的ArrayList,不用指定大小,可以动态增长,当超过分配内存最大值的时候,自动扩大一倍. 关于将linq查询结果转到dataview的问题 C#怎样实现软件的升级 求上传文件第三方控件 超难的反射问题 c#中如何在一个窗体中调用另外一个窗体的控件 分是怎么给的啊 怎么从事件的object sender等参数中得到触发此事件的控件的控件名?? 帮忙!求实现代码!关于C#中textbox的passwordchar! C++非托管程序,微软的态度是什么?那个晓得? 转换? 如何触发Panel上所有控件的Validated事件? 我该如何在web程序中取得activX控件中的一个TextBox中的值
al.Add("a");
al.Add(1);
al.Add(true);
string[] b = new string[a.Length];
a.CopyTo(b,0);
a =new string[10];
b.CopyTo(a,0);
string[] a = new string[5];
string[] b = new string[a.Length];
a.CopyTo(b,0);
a =new string[10];
b.CopyTo(a,0);
-------------------------------------------------------速度比ArrayList快,因为少了inbox和outBox的时间
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList[] cltext1=new ArrayList[3];
cltext1[0].Add("a");
//用同样的方式加;
}
}
}
{
Type t = origArray.GetType().GetElementType(); Array newArray = Array.CreateInstance(t,desiredSize); Array.Copy(origArray,0,newArray,0,Math.Min(origArray.Length,desiredSize)); return newArray;
} public void ArrayReDim()
{
int[] intAry = new int[0]; intAry = (int[])Redim(intAry,3);
intAry[0] = 1;
intAry[1] = 2;
intAry[2] = 3;
}