C#基础学习日志===>二维数组<===
来源:互联网 发布:大数据架构师简历 编辑:程序博客网 时间:2024/05/15 07:16
ArrayList和Array的区别
Array的容量是固定的,而ArrayList是可变的,
Array具有多维,而ArrayList是一维的
ArrayList提供添加,删除插入某一范围元素的方法而在Array中只能设置或获取一个元素的值
ArrayLlist是较为复杂的数组,它提供了一些Array未提供的功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Array
...{
class Program
...{
static void Main(string[] args)
...{ //使用ArrayList 前要引入命名空间System.Collections;
ArrayList arr = new ArrayList();
string str1;
while (true)
...{
Console.WriteLine("Add the word to ArrayList");
str1 = Console.ReadLine();
if (str1 =="end")
break;//只有输入"end" ,才会跳出while
arr.Add(str1);
for (int i = 0; i < arr.Count; i++)
Console.Write("{0} ", arr[i]);
Console.WriteLine();
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Array
...{
class Program
...{
static void Main(string[] args)
...{ //使用ArrayList 前要引入命名空间System.Collections;
ArrayList arr = new ArrayList();
string str1;
while (true)
...{
Console.WriteLine("Add the word to ArrayList");
str1 = Console.ReadLine();
if (str1 =="end")
break;//只有输入"end" ,才会跳出while
arr.Add(str1);
for (int i = 0; i < arr.Count; i++)
Console.Write("{0} ", arr[i]);
Console.WriteLine();
}
}
}
}
多维数组:
int[] arr1;//定义整形一维数组
int[,] arr2; // 定义整形二维数组
int[,] arr3= new int[2,3];
int[,] arr3 = new int[2, 3] ...{ ...{ 1, 3, 2 }, ...{ 4, 5, 6 } };
int[][] j2;//不规则数组,也称为数组的数组
int[][] j2 = new int[3][];
j2[0] = new int[] ...{ 1, 2, 3 };
j2[1] = new int[] ...{1,2,3,4,5,6 };
j2[2] = new int[] ...{ 1,3,2,4,5,6};
int[,] arr2; // 定义整形二维数组
int[,] arr3= new int[2,3];
int[,] arr3 = new int[2, 3] ...{ ...{ 1, 3, 2 }, ...{ 4, 5, 6 } };
int[][] j2;//不规则数组,也称为数组的数组
int[][] j2 = new int[3][];
j2[0] = new int[] ...{ 1, 2, 3 };
j2[1] = new int[] ...{1,2,3,4,5,6 };
j2[2] = new int[] ...{ 1,3,2,4,5,6};
static void Main(string[] args)
...{
int [,] arr = new int [4,6];
//给数组赋值
for (int i = 0; i < 4;i++ )
...{
for (int j = 0; j < 6; j++)
...{
arr[i, j] = (i + 1) * 10 + j + 1;
}
}
//输出数组结果
for (int i = 0; i < 4; i++)
...{
for (int j = 0; j < 6; j++)
...{
Console.Write("{0} ",arr[i,j ]);
}
Console.WriteLine();
}
Console.ReadLine();
}
...{
int [,] arr = new int [4,6];
//给数组赋值
for (int i = 0; i < 4;i++ )
...{
for (int j = 0; j < 6; j++)
...{
arr[i, j] = (i + 1) * 10 + j + 1;
}
}
//输出数组结果
for (int i = 0; i < 4; i++)
...{
for (int j = 0; j < 6; j++)
...{
Console.Write("{0} ",arr[i,j ]);
}
Console.WriteLine();
}
Console.ReadLine();
}
- C#基础学习日志===>二维数组<===
- C#基础学习日志===>二维数组<===
- C#基础学习日志===>数组<===
- C#基础学习日志===&gt;Method&lt;===
- 二维数组的指针 != 指针的指针
- http://poj.org/problem?id=1195二维树状数组
- 二维数组的指针 != 指针的指针
- C#基础学习日志===&amp;amp;amp;gt;命名空间的使用&amp;amp;amp;lt;===
- c语言==一维数组与二维数组(2)
- c语言==一维数组与二维数组的详解(9)
- Offer题1~3 重载=&指针和数组&二维数组替换
- C#之二维数组学习案例
- 写一个函数,使给定的一个二维数组(NXM)(N=M)转置,即行列互换(要求不额外创建二维数组)
- C#类==>数组相关
- http://acm.hdu.edu.cn/showproblem.php?pid=1892&&二维树状数组
- http://acm.hdu.edu.cn/showproblem.php?pid=2642&&二维树状数组
- Golang 实现根据变量初始化二维数组(所有值=0)
- c#界面==基础控件熟悉
- what is long tail effect
- Meta的http-equiv属性详解---转载
- 单片机控制继电器
- 单片机控制继电器电路
- 碎谈嵌入式学习要点
- C#基础学习日志===>二维数组<===
- C#基础学习日志===>二维数组<===
- 程序员保持身心健康的八种方式
- 毕生收集的一些卫星电视的地址
- 熵 (Entropy)
- linux面试题参考答案(转)
- HashTab 2.08 简体中文版
- 人生格言精选
- Linux的几个概念