C#里面有没有能够实现动态二维数组的集合类

zhuoran 2003-11-29 06:38:31
就是这个数组每一维里面的数据都要能够动态增减
...全文
456 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
NetAnt007 2003-12-30
  • 打赏
  • 举报
回复
arraylist aa = new arraylist();
aa.add(new arraylist());
aa[0].add("a");
aa[0].add("b");
访问:aa[0][0]...
aa[0][1] ...
zhvickie 2003-11-30
  • 打赏
  • 举报
回复
看看
rock1981 2003-11-30
  • 打赏
  • 举报
回复
ArrayList 最好不过了
cqing 2003-11-30
  • 打赏
  • 举报
回复
你在一个ArrayList里再放ArrayList不就行了?
hertcloud 2003-11-29
  • 打赏
  • 举报
回复
using System;
using System.Collections;//这个用来 调用ArrayList
namespace ArrayList1
{

class Class1
{

[STAThread]
static void Main(string[] args)
{

ArrayList myAll=new ArrayList();//定义一个ArrayList动态数组myAll
int temp;
Console.WriteLine("这是一个计算输入数之和的程序!!");
Console.WriteLine("请输入要累加的数字:");

do
{
temp=Convert.ToInt32(Console.ReadLine());
myAll.Add(temp);

}while(temp!=-1);
int b=0;

foreach(int temp2 in myAll)
{
b+=temp2;

}
Console.WriteLine("结果是:{0}",b);
}
}
}
FileNewExit 2003-11-29
  • 打赏
  • 举报
回复
动态增减?增可能不变,减能不变吗?原以为你自己先保存数据....

Try:

using System;
using System.Collections;

class Try{
static void Main(){
ArrayList[] array = new ArrayList[3];
int i = 0,j = 0;

for(i = 0; i < array.Length; i++){
array[i] = new ArrayList();
for(j = 0; j < 2 * i + 1; j++)
array[i].Add(i + j);
}

for(i = 0; i < array.Length; i++){
for(j = 0; j < array[i].Count; j++)
Console.Write(array[i][j] + " ");
Console.WriteLine();
}

//Some modifications
array[0].Add("Hello");
array[0].Add("World");
array[1].Add("Nice");
array[1].Add("Day");
array[2].RemoveAt(0);

for(i = 0; i < array.Length; i++){
for(j = 0; j < array[i].Count; j++)
Console.Write(array[i][j] + " ");
Console.WriteLine();
}
}
}



结果:
0
1 2 3
2 3 4 5 6
0 Hello World
1 2 3 Nice Day
3 4 5 6
zhuoran 2003-11-29
  • 打赏
  • 举报
回复
数组的内容都被改变了,能叫动态增减吗??
FileNewExit 2003-11-29
  • 打赏
  • 举报
回复
锯齿(jagged)数组就可以了:
using System;

class Jagged{
static void Main(){
int[][] array = new int[3][];
int i = 0,j = 0;
for(i = 0; i < array.Length; i++)
array[i] = new int[2 * i + 1];
for(i = 0; i < array.Length; i++)
for(j = 0; j < array[i].Length; j++)
array[i][j] = i + j;
for(i = 0; i < array.Length; i++){
for(j = 0; j < array[i].Length; j++)
Console.Write(array[i][j] + " ");
Console.WriteLine();
}
//resize it dynamically
for(i = 0; i < array.Length; i++)
array[i] = new int[2 * i + 5];
for(i = 0; i < array.Length; i++)
for(j = 0; j < array[i].Length; j++)
array[i][j] = i + j;
for(i = 0; i < array.Length; i++){
for(j = 0; j < array[i].Length; j++)
Console.Write(array[i][j] + " ");
Console.WriteLine();
}
}
}

结果:
0
1 2 3
2 3 4 5 6
0 1 2 3 4
1 2 3 4 5 6 7
2 3 4 5 6 7 8 9 10
jiezhi 2003-11-29
  • 打赏
  • 举报
回复
ArrayList

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧