社区
C#
帖子详情
C#里面有没有能够实现动态二维数组的集合类
zhuoran
2003-11-29 06:38:31
就是这个数组每一维里面的数据都要能够动态增减
...全文
538
9
打赏
收藏
C#里面有没有能够实现动态二维数组的集合类
就是这个数组每一维里面的数据都要能够动态增减
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用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
C#
数组和
集合类
详解
数组是一种指定长度和数据类型的对象,在实际应用中有一定的局限性。 集合正是为这种局限性而生的,集合的长度能根据需要更改,也允许存放任何数据类型的值。
15.
C#
数组(Array)声明与使用——《跟老吕学
C#
》
数组是
C#
中用于存储相同类型元素的固定大小集合。它们可以通过索引来访问和修改元素,并且支持多维数组。然而,在使用数组时必须小心,以避免出现索引越界等错误。在需要
动态
调整大小或更多功能的情况下,可以考虑使用
集合类
。
C#
数组学习
这里写目录标题一级目录二级目录三级目录 一级目录 二级目录 三级目录 一、一维数组 1.声明 type[] arrayName;//类型[] 数值名字。如:int[] intArr; 2. 初始化 int[] arr = new int[5];int[0] = 1;int[1] = 2; 声明时初始化:int[] arr = new int[5]{1,2,3,4,5}; string[] strArr; strArr = new string[7]{“Sun”,“Mon”,“Tue”,“Wed”,“Thu”
c#
中Dictionary、ArrayList、Hashtable和数组 Array
C#
集合类
Array Arraylist List Hashtable Dictionary Stack Queue
1.数组是固定大小的,不能伸缩。虽然System.Array.Resize这个泛型方法可以重置数组大小,
但是该方法是重新创建新设置大小的数组,用的是旧数组的元素初始化。随后以前的数组就废弃!而集合却是可变长的
2.数组要声明元素的类型,
集合类
的元素类型却是object.
3.数组可读可写不能声明只读数组。
集合类
可以
C#
list集合 重复元素 索引_编写高质量代码的100个建议16(选择正确的集合)
选择正确的集合前言 要选择正确的集合,首先需要了解一些数据结构的知识。所谓数据结构,就是相互之间存在一种或多种特定关系的数据元素的集合。 线性集合按存储方式又分为直接存储和顺序存储。所谓直接存储,是指该类型的集合数据元素可以直接通过下标(即index)来访问,在
C#
中直接存储的数据结构有三类: Array (包括数组和List)、string、...
C#
111,128
社区成员
642,535
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章