2017年11月3日 VS三大类&数组&VS的冒泡排序&集合&泛型集合

  三大类

共分为两个大类:

基本数据型&引用类型

基本数据型---值类型---整型---常用的整型: Int , 长整型:  Long, 小整型: byle, 中整型 short

                                --浮点型 -- 小浮点: float , 中浮点: double 大浮点: declaml 

                                --布尔型 -- bool(对错类型) -- ture||false

                                --字符型 -- char(单一字符)

引用类型 -- 字符串 -- string

               -- 时间日期 -- DateTime

数组

// 必须规定类型,必须规定长度

int[]  a = new int[添长度];

int[] b = new int[]{添数字};

string[] d = new string[]{"双引号内添加数字,以逗号隔开,并且一个双引号只能算一个"};

//当然不只是int型才可以,别的也可以

数组遍历

Console.WriteLine(b[里面添加索引值]);

Console.Read();

foreach(int c in b){

 Console.WriteLine(c);

//数组排序

 }

 数组赋值

a[索引值] = 数字(因为是int型);

二维数组

int[,] e = new int[1,1];

int[,] e1 = new int[,]{ { },{ },{ } };

二维数组取值

Console.WriteLine(e1[0,2])//从第零个取两个值

冒泡排序

 int[] a = new int[] { 9, 5, 8, 4, 2, 1 };
            for (int i = 0; i < a.Length - 1; i++)
            {
                for (int ib = i + 1; ib < a.Length; ib++)
                {
                    if (a[i] > a[ib])
                    {
                        int h = a[i];
                        a[i] = a[ib];
                        a[ib] = h;
                    }
                }
            }
            foreach (int k in a)
            {
                Console.WriteLine(k);
            }
           Console.Read();

 集合

//不需要规定类型和长度

外面要加:using System.Collections;

            ArrayList arr = new ArrayList();
            DateTime dt = new DateTime(2017, 11, 3);
//添加 arr.Add(
"abc"); arr.Add(123); arr.Add(true); arr.Add(dt); //集合遍历 //foreach(var x in arr) //{ // Console.WriteLine(x); //} //arr.Remove(123); //arr.RemoveAt(1); //arr.Reverse();//顺序翻转 arr.Insert(2, "ac"); Console.WriteLine(arr.Contains(123)); //foreach (var x in arr) //{ // Console.WriteLine(x); //} Console.Read();

泛型集合

//不规定长度 规定类型

//class要跟static void Main(string[] args)平级
class user{

 pubilc int user_id;

 pubilc string user_name;

}
//新建 Linst
<user> i = new Linst<user>();
//插入 user sj
= new user(); sj.user_id = 1; sj.user_name = "张三"; i.Add(sj); user ls = new user(); ls.user_id = 2; ls.user_name = "李四"; i.Add(ls); foreach(user x in i){ Console.WriteLine(x.user_id); }

List<类型或者Class的表名>  i = new List<类型或者Class的表名>();

添加

i.Add(比如123);

正则表达式

 string str = """;
            string temp = Console.ReadLine();
            Regex rx = new Regex("\d");
            if (rx.IsMatch(temp))
            {
                Console.WriteLine("非负整数");
            }else
            {
                Console.WriteLine("不是");
            }

数组

            try
            {
                int x = int.parse(temp);



                console.writeline("是数字");
            }
            catch
            {
                console.writeline("您输入的不是数字");
            }


            console.writeline(x);
原文地址:https://www.cnblogs.com/zJuevers/p/7780347.html