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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值