一维整型字符串数组、二维数组、锯齿数组
来源:互联网 发布:拍婚纱照攻略知乎 编辑:程序博客网 时间:2024/06/06 04:23
class Program
{
static void Main(string[] args)
{
//整数一维数组赋值的三种方法
int[] a = { 1, 2, 3, 4, 5, 6 }; //静态赋值
int[] b = new int [6] ;//动态赋值
int[] c = new int [6] { 1, 2, 3, 4, 5, 6 };
int[] d = new int[] { 1, 2, 3, 4, 5, 6 };
//字符串数组赋值的方法
string[] array = new string[5] { "bob", "jone", "joshua", "make", "jeson" };
/*for (int i = 0; i < 5; i++) {
Console.WriteLine(array[i]);
Console.ReadKey();
}*/
foreach (string f in array) { //遍历数组
Console.WriteLine(f);
}
//数字二维数组的赋值方法
int[,] erweri1 = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
/*for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
Console.WriteLine(erweri1[i, j]);
}
}*/
foreach (int g in erweri1) {
Console.WriteLine(g);
}
//数组的数组,锯齿数组
int[][] arr2 = {new int[]{1,2,3},new int[]{4,5},new int[]{6},new int[]{7,8,9}};
int[][] arr = new int[10][];
for (int i = 0; i < arr.GetLength(0); i++)
{
arr[i] = new int[i + 1];
}
arr[0][0] = 1;
for (int i = 1; i < arr.GetLength(0); i++)
{
for (int j = 0; j < i; j++)
{
arr[i][j + 1] = arr[i - 1][j];
arr[i][j] = arr[i][j] + arr[i - 1][j];
}
}
char c1 = ' ';
for (int i = 0; i < 10; i++)
{
for (int k = 10 - i; k > 0; k--)
{
Console.Write("{0}", c1);
}
for (int j = 0; j < i + 1; j++)
{
Console.Write(" {0}", arr[i][j]);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
{
static void Main(string[] args)
{
//整数一维数组赋值的三种方法
int[] a = { 1, 2, 3, 4, 5, 6 }; //静态赋值
int[] b = new int [6] ;//动态赋值
int[] c = new int [6] { 1, 2, 3, 4, 5, 6 };
int[] d = new int[] { 1, 2, 3, 4, 5, 6 };
//字符串数组赋值的方法
string[] array = new string[5] { "bob", "jone", "joshua", "make", "jeson" };
/*for (int i = 0; i < 5; i++) {
Console.WriteLine(array[i]);
Console.ReadKey();
}*/
foreach (string f in array) { //遍历数组
Console.WriteLine(f);
}
//数字二维数组的赋值方法
int[,] erweri1 = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
/*for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
Console.WriteLine(erweri1[i, j]);
}
}*/
foreach (int g in erweri1) {
Console.WriteLine(g);
}
//数组的数组,锯齿数组
int[][] arr2 = {new int[]{1,2,3},new int[]{4,5},new int[]{6},new int[]{7,8,9}};
int[][] arr = new int[10][];
for (int i = 0; i < arr.GetLength(0); i++)
{
arr[i] = new int[i + 1];
}
arr[0][0] = 1;
for (int i = 1; i < arr.GetLength(0); i++)
{
for (int j = 0; j < i; j++)
{
arr[i][j + 1] = arr[i - 1][j];
arr[i][j] = arr[i][j] + arr[i - 1][j];
}
}
char c1 = ' ';
for (int i = 0; i < 10; i++)
{
for (int k = 10 - i; k > 0; k--)
{
Console.Write("{0}", c1);
}
for (int j = 0; j < i + 1; j++)
{
Console.Write(" {0}", arr[i][j]);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
0 0
- 一维整型字符串数组、二维数组、锯齿数组
- C# 一维数组、二维数组(矩形数组)、交错数组(锯齿数组)的使用
- 一维数组、二维数组、字符串总结
- 字符串分割成一维数组、二维数组,一维数组与二维数组之间的转换
- 一维数组、二维数组
- 字符串数组、二维数组
- 二维数组,字符串数组
- Java数组 一维数组,二维数组
- array 数组 一维数组 二维数组
- Javascript - 数组 一维数组 二维数组
- JS-字符串分割为一维数组/二维数组
- 二级联动;字符串转一维数组,一维数组转二维数,二维数组转DataSet
- 锯齿数组
- 锯齿数组
- 锯齿数组
- C#数组 一维数组、二维数组、三维数组
- 一维数组,二维数组,三维数组,多维数组整理
- 整型数组(一)
- 存储过程,存储过程循环,一张表整列插入另一张表
- PC-Lint详解
- 探索 Pexpect,第 1 部分:剖析 Pexpect
- SQL SERVER 生成表结构的语句
- Ubuntu Server 将环境变量修改为英文,防止中文乱码
- 一维整型字符串数组、二维数组、锯齿数组
- 来自19位科技大亨的励志箴言(绝对值得收藏)
- sqlserver 取10到20条
- Objective-C学习笔记二:面向对象概述
- swift开发
- 探索 Pexpect,第 2 部分:Pexpect 的实例分析
- Android-编程小问题记录
- Hashtable 和 HashMap和concurrentHashMap和collections.synchronizedMap
- 巫神纪——血红