C#数组学习
2024-08-27 07:22:38
1.多维数组
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ControlProject
{
class Program
{
static void Main(string[] args)
{
//新建一个3*4的数组
string[,] person = new string[, ];
person[, ] = "姓名";
person[, ] = "性别";
person[, ] = "职业";
person[, ] = "年龄"; person[, ] = "神秘";
person[, ] = "帅哥";
person[, ] = "农民工";
person[, ] = "26岁"; person[, ] = "小白";
person[, ] = "男";
person[, ] = "大宅男";
person[, ] = "27岁"; StringBuilder sb = new StringBuilder();//用一个可变字符串对象来接收循环中的值 //取出数组二维数组的长度
int x = person.GetLength();
int y = person.GetLength(); for (int i = ; i < x; i++)
{
for (int j = ; j < y; j++)
{
sb.Append(person[i, j] + " | ");
}
sb.Append("\n----------------------------------------------\n");
} Console.WriteLine(sb.ToString());
}
}
}
2.锯齿数组
在锯齿数组中,每一行都可以有不同的大小。
锯齿数组的效率比多维数组要高很多。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ControlProject
{
class Program
{
static void Main(string[] args)
{
int[][] myint = new int[][];
myint[] = new int[] { , , };
myint[] = new int[] { , };
myint[] = new int[] { , , }; foreach (int[] i in myint)
{
foreach (int x in i)
{
Console.Write(x + ",");
}
Console.WriteLine();
} }
}
}
3.Array类
数组类型是从抽象基类型Array派生的引用类型,
由于此类型实现了IEnumerable和IEnumerable<(Of<(T>)>), 因此可以对C#中的所有数组使用foreach迭代
4.ArrayList
最新文章
- Effective前端2:优化html标签
- U盘容量变小的处理方式
- JsonString,字典,模型之间相互转换
- 调试SQLSERVER (一)生成dump文件的方法
- Win7 64位安装MySQL
- COB(Chip On Board)的製程簡單介紹
- 一个用于每一天JavaScript示例-SVG中间javaScript画廊
- Scrum与高效能人士
- Http状态码大全(来自菜鸟教程)
- javaSE_05Java中方法(函数)与重载、递归-思维导图
- win7 mysql 数据库轻松实现数据库定时备份
- 扩展资源服务器解决oauth2 性能瓶颈
- TensorFlow实战Google深度学习框架8-9章学习笔记
- Daily Scrum- 12/31
- cf220B莫队
- linux 删除开头是减号的文件名
- 开发十年,只剩下这套Java开发体系了
- QT中添加 动态库(.so) 和 静态库 (.a) 的方法
- JAVA框架 Spring AOP--切入点表达式和通知类型
- code vs 1094 FBI树 2004年NOIP全国联赛普及组