数组

本文详细探讨了数组这一基本数据结构,从定义、类型、内存分配到操作方法,全面解析了数组的工作原理。通过实例分析,展示了数组在存储和检索大量数据时的优势,并讨论了数组在实际编程中的常见应用和注意事项。
摘要由CSDN通过智能技术生成
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Beas05
{
    class Program
    {
        static void Main(string[] args)
        {
            //数据类型[] 数组名 = new 数据类型[数组长度];
            //int[] ints = new int[5];
            //数组索引 从0开始 对数组的数组元素进行赋值从0开始
            //ints[0] = 1;
            //ints[1] = 2;
            //ints[2] = 3;
            //ints[3] = 4;
            //ints[4] = 5;
            //数据类型[] 数组名 = { 值1,值2,值3,值4 };
            //int[] ints = { 1, 2, 3, 4, 5 };
            //Console.WriteLine(ints.Length);

            //数据类型[,] 数组名 = new 数据类型[数值1, 数值2];
            //int[5, 10] 5行10列(每一行10个列)
            //所以的数据类型  都会有默认值  值类型 关键字 蓝色

            //int[,] ints = new int[5,10];
            //ints[0, 0] = 1;
            //ints[0, 1] = 2;
            //Console.WriteLine(ints[3,4]);
            //数据类型[,] 数组名 = new 数据类型[,] { { 值1,值2 }, { 值1,值2 }, { 值1,值2 } };
            //int[,] ints = new int[,] { { 1, 1 }, { 2, 2 },{ 3, 3 }, { 4, 4 } };
            //Console.WriteLine(ints[3,1]);



            //遍历数组的方式
            //for
            //int[] ints = { 100, 200, 300, 400, 500 };
            //for (int i = 0; i < ints.Length; i++)
            //{
            //    Console.WriteLine(ints[i]);
            //}
            //Console.WriteLine("----------------------");
            //foreach(元素类型 item in 集合或者数组名)
            //是根据迭代  循环一次 判断是否存在 如果存在着获取下一个信息
            //    foreach (int item in ints)
            //    {
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值