c# list<T>操作实例

5b61c2799e4dffe1107225def9d29808.png

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
             List<string[]> str1 = new List<string[]> { };
             List<string[]> str2 = new List<string[]> { };
             string[] class1 = { "牛连山", "数学成绩", "58" };
             string[] class2 = { "孙少华", "数学成绩", "37" };
             string[] class3 = { "蒋大帅", "数学成绩", "45" };
             string[] class4 = new string[20];
             //str1.AddRange(str2);
             str1.Add(class1);
             str1.Add(class2);
             str1.Add(class3);
             Console.WriteLine("输出1:"+str1.Count());//结果是3
             Console.WriteLine("输出2:"+str1[0][0]);
             Console.WriteLine("输出3:"+(str1.OrderBy(s => s[2]).ToList())[2][2]);
       


            List<string> lists = new List<string> { };
            lists.Add("str");
            lists.Add("hello");
            string[] str = lists.ToArray();
            foreach(string aa in str)
            {
                Console.WriteLine(aa);
            }


            List<byte[]> byt1 = new List<byte[]> { };
            List<byte[]> byt2 = new List<byte[]> { };
            List<byte> byt3 = new List<byte> { };
            byte[] by1 = { 0x11, 0x03, 0x05 ,0x24};
            byte[] by2 = { 0xA9, 0x01, 0x56 };
            byte[] by3 = { 0x04, 0x02, 0x07 };
            byte[,] by4 = new byte[9,2];
            byte[] by5 = new byte[9];
            byte zijie;
            byt1.Add(by1);
            byt1.Add(by2);
            byt1.Add(by3);
            byt2.Add(by1);


            Console.WriteLine("输出4:" + byt1.Count());
            byt2 = byt1.OrderBy(s => s[1]).ToList();
            Console.WriteLine("输出字节:{0}-{1}-{2}", byt2[0][0],byt2[0][1],byt2[0][2]);
            zijie = byt2[0][0];
            Console.WriteLine("输出5:" + zijie);
            by4[0,1] = 0x11;
            Console.WriteLine(by4[0, 1].ToString());
            Console.WriteLine(byt2.ToArray()[0][0].ToString());
            foreach(byte[] item in byt2)
            {
              var  listdata = item.ToList();
                   foreach(var item1 in item)
                    Console.Write("--"+item1.ToString());
                Console.Write("--"+listdata.Count().ToString());
            }


                
            Console.ReadKey();


        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值