C#的基礎(chǔ)語法示例還算是全吧

#region//引入命名空間
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
#endregion
#region//命名規(guī)則
//變量命名    在簡單的循環(huán)語句中計數(shù)器變量使用 i, j, k, l, m, n
// Camel 命名規(guī)則,即第一個單詞首字母小寫,其余單詞首字母大寫
//屬性命名    命名名稱應(yīng)該為名詞及名詞短語,使用Pascal規(guī)則,即每個單詞首字母大寫
//枚舉命名    對于 Enum 類型和值名稱使用 Pascal 大小寫咖耘。少用縮進(jìn)谤牡,
//不要在 Enum 類型名稱上使用 Enum 后綴壹无。
//對大多數(shù) Enum 類型使用單數(shù)名稱拍埠,但是對作為位域的 Enum 類型使用復(fù)數(shù)名稱。
//方法命名    對方法名采用一致的動詞/賓語或賓語/動詞順序速和。
//推薦名稱應(yīng)該為動詞或動詞短語,使用Pascal規(guī)則
//集合命名    使用Pascal規(guī)則。名稱應(yīng)該為名詞及名詞短語
//名稱后面追加“Collection”或者加復(fù)數(shù)形式-s也行
//接口命名    接口名稱應(yīng)該為名詞及名詞短語或者描述其行為的形容詞剥汤,盡可能使用完整的詞
//使用字符I為前綴颠放,并緊跟一個大寫字母,使用Pascal規(guī)則
//類命名    為名詞及名詞短語吭敢,盡可能使用完整的詞碰凶,使用Pascal規(guī)則
//不要使用類前綴 - 不要使用下劃線字符 (_)。
//使用復(fù)合單詞命名派生的類鹿驼。派生類名稱的第二個部分應(yīng)當(dāng)是基類的名稱
//創(chuàng)建類時不要與內(nèi)置類名相同欲低,以免混淆
#endregion
#region//命名空間
namespace ConsoleApp31
{
    #region//抽象類 1 2
    //抽象使用關(guān)鍵字 abstract
    //抽象類不能實例化,抽象方法也不能直接實現(xiàn)畜晰,必須在抽象的派生類中重寫
    //如果類包含抽象方法砾莱,這個類就必須是抽象類
    //繼承抽象類時,需要實現(xiàn)所有抽象成員
    #region//抽象類以及抽象方法
    public abstract class MyClass1//抽象類
    {
        public abstract void OutPutX(string x);//抽象方法輸出輸入的字符串x
                                               //因為是抽象方法凄鼻,所以不能對他實現(xiàn)腊瑟。
                                               //抽象方法必須在非抽象的派生類中重寫聚假。
    }
    #endregion
    #region//抽象類繼承以及抽象方法重寫
    public class MyClass2 : MyClass1//派生類繼承抽象類
                                    //繼承抽象類必須實現(xiàn)抽象類中所有抽象成員
    {
        public override void OutPutX(string x)//實現(xiàn)抽象基類的派生方法
                                              //對抽象方法重寫,使用 override 關(guān)鍵字
        {
            WriteLine(x);
        }
    }
    #endregion
    #endregion
    #region//普通類 3
    //類可以包含許多元素
    //常見的有字段扫步、屬性魔策、方法、構(gòu)造函數(shù)
    public class MyClass3
    {
        #region//字段
        //定義三個私有字段河胎,
        private int studentId;//學(xué)生的id闯袒,
        private string studentName;//學(xué)生的名字
        private int studentAge;//學(xué)生的年齡
        #endregion
        #region//屬性
        public int StudentId//生成學(xué)生id的屬性
                            //通過公有屬性訪問私有字段
                            //屬性必須有g(shù)et訪問器,用于讀游岳,set訪問器可以省略政敢,即只讀不寫
        {
            get { return studentId; }//get訪問器,用于讀,返回私有學(xué)生id
            set { studentId = value; }//set訪問器胚迫,用于寫喷户。
        }
        public String StudentName//生成學(xué)生姓名的屬性
        {
            get { return studentName; }
            set { studentName = value; }
        }
        public int StudentAge//生成學(xué)生年齡的屬性
        {
            get { return studentAge; }
            set//對于寫輸入做判斷,如果大于大于0访锻,正常輸入褪尝,如果小于0,設(shè)置為0
            {
                if (value >= 0)
                {
                    studentAge = value;
                }
                else
                {
                    studentAge = 0;
                }
            }
        }
        #endregion
        #region//構(gòu)造函數(shù)
        //構(gòu)造函數(shù)用于初始化賦值
        //如果不寫會生成默認(rèn)的構(gòu)造函數(shù)
        //參數(shù)可有可無期犬,但是要注意實例化時要根據(jù)構(gòu)造函數(shù)是否有參數(shù)決定是否傳參
        //如果手動寫構(gòu)造函數(shù)河哑,必須對所有字段賦值。
        public MyClass3(int StudentId, String StudentName, int StudentAge)
        {
            this.studentId = StudentId;
            this.studentName = StudentName;
            this.studentAge = StudentAge;
        }
        #endregion
        #region//方法
        //靜態(tài)方法使用關(guān)鍵字 static
        //靜態(tài)方法屬于類中所有元素
        //調(diào)用靜態(tài)方法通過類調(diào)用
        public static void OutPutMyClass3AllVariable(params MyClass3[] a)//定義靜態(tài)方法龟虎,輸出類中實例的所有字段
        {
            foreach (MyClass3 i in a)
            {
                WriteLine("{0}  {1}  {2}", i.StudentId, i.StudentName, i.StudentAge);
                WriteLine("**************");
            }
            
        }
        //實例方法璃谨,實例方法屬于類的每個實例
        //調(diào)用實例方法通過實例調(diào)用
        public void OutPutMyClass3Variable()//定義實例方法,輸出實例的所有字段
        {
            WriteLine("{0}  {1}  {2}",StudentId,StudentName,StudentAge);
        }
        #endregion

    }

    #endregion
    #region//方法重載 4
    //方法重載即方法名相同鲤妥,但是方法的參數(shù)個數(shù)或數(shù)據(jù)類型不同
    //只能根據(jù)參數(shù)來判定選擇使用哪個方法佳吞,與方法內(nèi)容返回類型無關(guān)。
    public class MyClass4
    {
        public void MyMethod()
        {
            WriteLine("無參數(shù)無返回值");
        }
        public void MyMethod(int x)
        {
            WriteLine("有一個整形參數(shù)無返回值");
        }
        public void MyMethod(string s)
        {
            WriteLine("有一個字符串參數(shù)無返回值");
        }
        public void MyMethod(int x,int y)
        {
            WriteLine("有兩個整形參數(shù)無返回值");
        }
        public void MyMethod(int x,string s)
        {
            WriteLine("一個整形參數(shù)棉安,一個字符串參數(shù)無返回值");
        }
        public void MyMethod(string s,int x)
        {
            WriteLine("一個字符串參數(shù)一個整形參數(shù)參數(shù)無返回值");
        }
    }
    #endregion
    #region//方法重寫與隱藏方法 5 6
    public class MyClass5
    {
        public virtual void EmptyMethod()//使用virtual標(biāo)注一個虛方法底扳,可以在派生類中重寫
        {
            WriteLine("這是一個基類虛方法");
        }
        public void OrdinaryMethod()
        {
            WriteLine("這是一個普通的基類方法");
        }

        //存在以下object方法可以被重寫
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override string ToString()
        {
            return base.ToString();
        }
    }
    public class MyClass6 : MyClass5
    {
        public override void EmptyMethod()//重寫虛方法需要使用 override 關(guān)鍵字
        {
            WriteLine("這是基類虛方法重寫");
        }
        new public void OrdinaryMethod()
        {
            WriteLine("對基類方法隱藏");
        }
    }
    #endregion
    #region//派生類的構(gòu)造函數(shù) 7 8
    public class MyClass7
    {
        public int ID;
        public string name;


        public MyClass7(int ID, string name)//基類構(gòu)造函數(shù)
        {
            this.ID = ID;
            this.name = name;
        }
    }
    public class MyClass8:MyClass7
    {
        public MyClass8(int ID,string name)://派生類構(gòu)造函數(shù)
            base(ID,name)
        {

        }
    }
    #endregion
    #region//接口 9
    public interface IOutPut//定義一個接口
    {
        void OutPut(string str);//接口方法,不用實現(xiàn)
    }
    public class MyClass9 : IOutPut//繼承接口垂券,必須實現(xiàn)接口的方法
    {
        public void OutPut(string str)//對接口方法的實現(xiàn)
                                      //可以繼承多個接口
                                      //實現(xiàn)接口方法時方法的簽名不能改變
        {
            WriteLine(str);
        }
    }
    #endregion
    #region//泛型 10 11 12 13
    #region//泛型接口
    public interface IOutPut<T>//泛型接口
    {
        void OutPut(T x);
    }
    #endregion
    #region//泛型類
    public class MyClass10<T1,T2>//泛型類
    {
        public T1 studentId;
        public T2 studentName;
        public T1 studentAge;
        public MyClass10(T1 studentId, T2 studentName, T1 studentAge)
        {
            this.studentId = studentId;
            this.studentName = studentName;
            this.studentAge = studentAge;
        }
    }

    #endregion
    #region//泛型類花盐,泛型接口繼承
    public class MyClass11<T1,T2,T>:MyClass10<T1,T2>, IOutPut<T>//泛型類繼承
                                                                //繼承泛型類,繼承泛型接口
    {
        public MyClass11(T1 studentId, T2 studentName, T1 studentAge)://對于基類有構(gòu)造函數(shù)的派生類需要生成派生類
            base(studentId, studentName, studentAge)
        {

        }
        #region//泛型接口方法實現(xiàn)
        public void OutPut(T x)//對繼承接口的方法實現(xiàn)
        {
            WriteLine(x);
        }
        #endregion

    }
    public class MyClass12:MyClass10<int,string>, IOutPut<string>//非泛型類也可以繼承泛型類菇爪,泛型接口
        //繼承時類必須在接口前面
    {
        public MyClass12(int studentId, string studentName, int studentAge) ://對于基類有構(gòu)造函數(shù)的派生類需要生成派生類
           base(studentId, studentName, studentAge)
        {

        }
        public void OutPut(string x)
        {
            WriteLine(x);
        }
    }
    #endregion
    #region//泛型約束
    // sturct   對于結(jié)構(gòu)約束算芯,泛型必須是值類型
    // class    類約束指定類型T必須是引用類型
    //IFoo  指定類型T必須實現(xiàn)接口IFoo
    //Foo   指定類型T必須派生自基類Foo
    //new() 這個是一個構(gòu)造函數(shù)約束,指定類型T必須有一個默認(rèn)構(gòu)造函數(shù)
    //T2    這個約束也可以指定凳宙,類型T1派生自泛型類型T2
    public class MyClass13<T>
        where T:struct//約束泛型必須是值類型
        //可以同時又多個約束熙揍,用逗號分隔。
    {
        public T x;
        public static void OutPutX(T x)
        {
            WriteLine(x);
        }
    }
    #endregion
    #region//協(xié)變抗變
    //如果泛型類用 out 關(guān)鍵字標(biāo)注氏涩,那么泛型接口就是協(xié)變的
    //返回值類型只能是T
    public interface ISquare<out T>
    {
        T Square(int x);
    }
    //如果泛型類型使用 in 關(guān)鍵字標(biāo)注届囚,那么泛型接口就是抗變的
    //接口只能將泛型類型T用作其方法的輸入
    public interface Iresist<in T>
    {
        void show(T x);
    }
    #endregion
    #endregion
    #region//數(shù)組 14
    public class MyClass14<T>
    {
        public static void ShowArrayAll(params T[] x)//創(chuàng)建一個輸出所有數(shù)組元素的方法
        {
            foreach (var i in x)
            {
                WriteLine(i);
            }
        }
        public static void ShowTwoArrayAll(T[,] x)//創(chuàng)建一個輸出所有二維數(shù)組元素的方法
                                                  //二維數(shù)組不需要 params
        {
            for (int i = 0; i < x.GetLength(0); i++)
            {
                for (int j = 0; j < x.GetLength(1); j++)
                {
                    Write("{0} ", x[i, j]);
                }
                WriteLine();
            }
        }
        public static void ShowSawtoothArrayAll(T[][] x)//輸出鋸齒數(shù)組中所有元素
        {
            for (int i = 0; i < x.Length; i++)
            {
                for (int j = 0; j < x[i].Length; j++)
                {
                    Write("{0} ", x[i][j]);
                }
                WriteLine();
            }
        }
    }
    #endregion
    #region//枚舉 15
    public class MyClass15
    {
        public enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat }
        //枚舉是一組命名整型常量有梆。枚舉類型是使用 enum 關(guān)鍵字聲明的。
        //枚舉是值類型意系。
        //枚舉包含自己的值泥耀,且不能繼承或傳遞繼承。
        public enum Color
        {
            red=100,//可以直接對枚舉中元素賦值蛔添,
            greed,//未賦值元素依據(jù)上一個元素的值自增
            blue = 50//手動賦值的情況可以忽略從上到下的大小關(guān)系痰催,但是不建議這樣
        }
    }
    #endregion
    #region//運(yùn)算符重載 16
    public class MyClass16
    {
        public int length;//長
        public int breadth;//寬
        public static MyClass16 operator +(MyClass16 a, MyClass16 b)
        //對運(yùn)算符重寫需要使用 operator 關(guān)鍵字
        //后面加上要重寫的運(yùn)算符
        {
            //這里傳入兩個實例,將實例的每個字段相加迎瞧,然后返回屬性
            MyClass16 x = new MyClass16();
            x.length = a.length + b.length;
            x.breadth = a.breadth + b.breadth;
            return x;
        }
    }
    #endregion
    #region//委托 17
    //委托(Delegate) 是存有對某個方法的引用的一種引用類型變量夸溶。引用可在運(yùn)行時被改變。
    //使用 delegate  關(guān)鍵字聲明委托
    //一旦聲明了委托類型凶硅,委托對象必須使用 new 關(guān)鍵字來創(chuàng)建缝裁,且與一個特定的方法有關(guān)。
    public class MyClass17
    {
        #region//用于普通委托的方法
        public static int F1(int x)//隨便寫兩個方法
        {
            return x;
        }
        public static int F2(int x)
        {
            return x - 1;
        }
        #endregion
        #region//用于多播委托的方法
        public static void  F3()//隨便寫兩個方法
        {
            WriteLine("這是第一個委托");
        }
        public static void F4()
        {
            WriteLine("這是第二個委托");
        }
        #endregion
    }
    public delegate int WT(int x);//聲明一個委托足绅,規(guī)定返回類型捷绑,需要的參數(shù)
    public delegate void WT1();//這個委托一會用于演示多播委托
    public delegate void WT2(string str);//用于創(chuàng)建匿名方法
    #endregion
    #region//lambda表達(dá)式 18
    public class MyClas18
    {
        //=>左邊方法,右邊方法體氢妈,不需要return
        public static int F1(int x) => x * x;//一個簡單的lambda表達(dá)式
        public static void F2(int x) => WriteLine(x);
    }
    #endregion
    #region//linq 19
    public class MyClass19
    {
        public int id;
        public int mark;
        public static List<MyClass19> Establish()
        {
            var listlinq = new List<MyClass19>();
            Random r = new Random();
            for (int i = 0; i < 100; i++)
            {
                MyClass19 x = new MyClass19();
                x.id = i;
                x.mark = r.Next(0, 100);
                listlinq.Add(x);
            }
            return listlinq;
        }
        public static void PutOutAllList(List<MyClass19> listlinq)//輸出列表
        {
            foreach(var i in listlinq)
            {
                WriteLine("ID是 {0} 分?jǐn)?shù)是{1}",i.id,i.mark);
            }
        }
    }
    #endregion
    #region//主函數(shù)類
    class Program
    {
        #region//入口函數(shù)
        static void Main(string[] args)
        {
            #region//對MyClass3實例化操作
            MyClass3 lihua = new MyClass3(100,"lihua",23);
            lihua.OutPutMyClass3Variable();
            MyClass3 yb = new MyClass3(1614,"yb",22);
            MyClass3[] a = new MyClass3[] { lihua,yb };
            WriteLine("----------------------------");
            MyClass3.OutPutMyClass3AllVariable(a);
            #endregion
            #region//MyClass4方法重載的檢驗
            WriteLine("----------------------------------");
            WriteLine("對MyClass4方法重載的檢驗");
            MyClass4 v = new MyClass4();//因為都是實例方法胎食,所以需要先實例化
            v.MyMethod();
            v.MyMethod(777);
            v.MyMethod("asdw");
            v.MyMethod(777,888);
            v.MyMethod(777,"asdw");
            v.MyMethod("asdw",777);
            #endregion
            #region//MyClass5,MyClass6虛方法重寫允懂,隱藏基類方法
            WriteLine("---------------------");
            WriteLine("對MyClass5,MyClass6虛方法重寫衩匣,隱藏基類方法檢測");
            MyClass5 c5 = new MyClass5();
            MyClass6 c6 = new MyClass6();
            c5.EmptyMethod();
            c6.EmptyMethod();
            c5.OrdinaryMethod();
            c6.OrdinaryMethod();
            #endregion
            #region//MyClass7蕾总,MyClass8派生類構(gòu)造函數(shù)檢驗
            WriteLine("-----------------------");
            WriteLine("MyClass7,MyClass8派生類構(gòu)造函數(shù)檢驗");
            MyClass7 c7 = new MyClass7(777,"asdw");
            MyClass8 c8 = new MyClass8(888,"qwe");
            WriteLine("{0} {1}", c7.ID, c7.name);
            WriteLine("{0} {1}", c8.ID, c8.name);
            #endregion
            #region//MyClass9接口檢測
            MyClass9 c9 = new MyClass9();
            c9.OutPut("實現(xiàn)接口方法");
            #endregion
            #region//泛型檢測 10 11 12 13
            MyClass10<int, string> c10 = new MyClass10<int, string>(101, "qwe",10);
            MyClass11<int, string,string> c11 = new MyClass11<int, string,string>(102, "asdw", 25);
            WriteLine("{0}  {1}  {2}",c10.studentId,c10.studentName,c10.studentAge);
            WriteLine("{0}  {1}  {2}", c11.studentId, c11.studentName, c11.studentAge);
            c11.OutPut("這是一個派生接口的方法實現(xiàn)");
            MyClass12 c12 = new MyClass12(102,"zxc",789);
            c12.OutPut("這是非泛型類繼承泛型接口");
            MyClass13<int>.OutPutX(777);//必須是值類型
            #endregion
            #region//數(shù)組 14
            #region//一維數(shù)組
            WriteLine("一維數(shù)組");
            WriteLine("---------------------");
            int[] myArray1 = new int[4];//聲明一個數(shù)組長度為4的整形一維數(shù)組
            myArray1[0] = 100;
            myArray1[1] = 777;
            myArray1[2] = 888;
            myArray1[3] = 1234;
            MyClass14<int>.ShowArrayAll(myArray1);//調(diào)用方法輸出數(shù)組的所有元素
            int[] myArray2 = { 1,2,3,4,5};//聲明數(shù)組的另一種方式
            MyClass14<int>.ShowArrayAll(myArray2);
            WriteLine(myArray1.Length);//輸出數(shù)組的長度
            #endregion
            #region//多維數(shù)組
            int[,] myArray3 = new int[2, 3];//創(chuàng)建一個兩行三列的數(shù)組
            WriteLine("二維數(shù)組");
            WriteLine("---------------------------");
            for (int i = 0; i<myArray3.GetLength(0); i++)
            {
                for (int j = 0; j < myArray3.GetLength(1); j++)
                {
                    //WriteLine("{0}  {1}", i,j);
                    myArray3[i, j] = i + j;
                }
            }
            MyClass14<int>.ShowTwoArrayAll(myArray3);
            WriteLine("-----------------------");
            int[,] myArray4 = new int[2, 3] { { 4,5,6},{7,8,9 } };//同樣可以初始化時直接賦值
            MyClass14<int>.ShowTwoArrayAll(myArray4);
            #endregion
            #region//鋸齒數(shù)組
            WriteLine("鋸齒數(shù)組");
            WriteLine("-------------------");
            int[][] myArray5 = new int[3][];//鋸齒數(shù)組在創(chuàng)建的時候必須規(guī)定該數(shù)組最外層行數(shù)
            myArray5[0] = new int[]{ 1,3};
            myArray5[1] = new int[] { 5,6,7,8 };
            myArray5[2] = new int[] { 777 };
            MyClass14<int>.ShowSawtoothArrayAll(myArray5);
            #endregion
            #endregion
            #region//枚舉檢測 15
            WriteLine("------------------------");
            WriteLine("枚舉檢測");
            int d = (int)MyClass15.Day.Tue;//枚舉類表中每個整形符號代表一個整形值琅捏,從0開始
            WriteLine(d);
            int c1 = (int)MyClass15.Color.blue;
            WriteLine(c1);
            #endregion
            #region//運(yùn)算符重載檢測 16
            WriteLine("---------------");
            WriteLine("運(yùn)算符重載檢測");
            MyClass16 aa = new MyClass16();
            MyClass16 bb = new MyClass16();
            aa.length = 100;
            aa.breadth = 50;
            bb.length = 77;
            bb.breadth = 40;
            MyClass16 xx = aa + bb;//用一個新的實例接收返回值
            WriteLine("{0}  {1}",xx.length,xx.breadth);
            #endregion
            #region//類型轉(zhuǎn)換示例
            WriteLine("------------------");
            WriteLine("類型轉(zhuǎn)換示例");
            //類型轉(zhuǎn)換分為兩種生百,隱式類型轉(zhuǎn)換和顯示類型轉(zhuǎn)換
            //隱式類型轉(zhuǎn)換,從小的整數(shù)類型轉(zhuǎn)換為大的整數(shù)類型柄延,從派生類轉(zhuǎn)換為基類蚀浆。
            //只要保證數(shù)據(jù)不會丟失
            int a1 = 100;
            long a2 = a1;
            //int a3 = a2;會報錯,只能大的轉(zhuǎn)換為小的
            WriteLine("{0}   {1}",a1.GetType(),a2.GetType());
            //還有另一種是顯示類型轉(zhuǎn)換
            //即強(qiáng)制類型轉(zhuǎn)換搜吧。顯式轉(zhuǎn)換需要強(qiáng)制轉(zhuǎn)換運(yùn)算符市俊,而且強(qiáng)制轉(zhuǎn)換會造成數(shù)據(jù)丟失。
            long b1 = 200;
            int b2 = (int)b1;//顯示類似轉(zhuǎn)換用括號
            WriteLine("{0}   {1}", b1.GetType(), b2.GetType());
            #endregion
            #region//委托 17
            WriteLine("------------------");
            WriteLine("委托實踐");
            #region//普通委托
            //一旦聲明了委托類型滤奈,委托對象必須使用 new 關(guān)鍵字來創(chuàng)建摆昧,且與一個特定的方法有關(guān)。
            //實例化委托
            WT w1 = new WT(MyClass17.F1);
            WT w2 = new WT(MyClass17.F2);
            WriteLine("{0}  {1}",w1(10),w2(100));
            #endregion
            #region//多播委托
            //多播委托
            //使用 + 將多個委托連接
            //按照順序調(diào)用多播委托蜒程,委托的簽名必須的void绅你,否則只返回最后一個
            WT1 w3 = new WT1(MyClass17.F3);
            WT1 w4 = new WT1(MyClass17.F4);
            WT1 ww;
            ww = w3 + w4;
            ww();//調(diào)用多播委托
            #endregion
            #region//匿名方法
            //提供了一種傳遞代碼塊作為委托參數(shù)的技術(shù)伺帘。
            //匿名方法是沒有名稱只有主體的方法。
            //在匿名方法中不需要指定返回類型忌锯,它是從方法主體內(nèi)的 return 語句推斷的伪嫁。
            WT2 www = delegate (string str)
            {
                WriteLine("這是匿名方法 {0}",str);
            };
            www("asdw");
            #endregion
            #endregion
            #region//集合
            WriteLine("---------------");
            WriteLine("集合檢測");
            #region//列表
            var list1 = new List<int>();
            list1.Add(0);
            list1.Add(10);
            list1.Add(5);
            foreach(var i in list1)
            {
                WriteLine(i);
            }
            WriteLine("-------------");
            #endregion
            #region//隊列 先進(jìn)先出
            var list2 = new Queue();
            list2.Enqueue(1);
            list2.Enqueue("asdw");
            list2.Enqueue(7777);
            foreach(var i in list2)
            {
                WriteLine(i);
            }
            #endregion
            #region//棧堆 后進(jìn)先出
            WriteLine("-----------------");
            var list3 = new Stack();
            list3.Push(75);
            list3.Push("qwe");
            list3.Push(999999999999);
            foreach (var i in list3)
            {
                WriteLine(i);
            }
            #endregion
            #endregion
            #region//lambda 18
            WriteLine("------------------");
            WriteLine("lambda表達(dá)式");
            int ss =MyClas18.F1(10);
            WriteLine(ss);
            MyClas18.F2(7777);
            #endregion
            #region//linq 19 看另一篇文章吧[LINQ](http://www.reibang.com/writer#/notebooks/46905221/notes/75179989/preview)

            //from 查詢表達(dá)式必須以 from 子句開頭 代表從
            //如 from i in asdw      asdw是要操作的目標(biāo),i是asdw的每個對象
            //where 限定條件 用于指定將在查詢表達(dá)式中返回數(shù)據(jù)源中的哪些元素偶垮。
            //select 查詢 指定在執(zhí)行查詢時產(chǎn)生的值的類型张咳。
            //group
            WriteLine("------------------------");
            WriteLine("LINQ實踐");
            #region//創(chuàng)建數(shù)據(jù)
            var listlinq =  MyClass19.Establish();
            MyClass19.PutOutAllList(listlinq);
            #endregion
            #region//查詢數(shù)據(jù)
            var s = from i in listlinq
                    where ((i.mark > 95 || i.mark < 10) && i.id >50)
                    orderby i.mark descending//依照分?jǐn)?shù)排序 ascending正序,descending倒序
                    select i;
            WriteLine("**********************************");
            List<MyClass19> evenlist;
            evenlist = s.ToList<MyClass19>();//將查詢結(jié)果隱式轉(zhuǎn)換為MyClass19類型的列表
            MyClass19.PutOutAllList(evenlist);//輸出這個列表
            #endregion
            #endregion
            ReadKey();
        }
        #endregion
    }
    #endregion
}
#endregion

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末针史,一起剝皮案震驚了整個濱河市晶伦,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌啄枕,老刑警劉巖婚陪,帶你破解...
    沈念sama閱讀 216,919評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異频祝,居然都是意外死亡泌参,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,567評論 3 392
  • 文/潘曉璐 我一進(jìn)店門常空,熙熙樓的掌柜王于貴愁眉苦臉地迎上來沽一,“玉大人,你說我怎么就攤上這事漓糙∠巢” “怎么了?”我有些...
    開封第一講書人閱讀 163,316評論 0 353
  • 文/不壞的土叔 我叫張陵昆禽,是天一觀的道長蝗蛙。 經(jīng)常有香客問我,道長醉鳖,這世上最難降的妖魔是什么捡硅? 我笑而不...
    開封第一講書人閱讀 58,294評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮盗棵,結(jié)果婚禮上壮韭,老公的妹妹穿的比我還像新娘。我一直安慰自己纹因,他們只是感情好喷屋,可當(dāng)我...
    茶點故事閱讀 67,318評論 6 390
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著瞭恰,像睡著了一般逼蒙。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,245評論 1 299
  • 那天是牢,我揣著相機(jī)與錄音僵井,去河邊找鬼。 笑死驳棱,一個胖子當(dāng)著我的面吹牛批什,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播社搅,決...
    沈念sama閱讀 40,120評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼驻债,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了形葬?” 一聲冷哼從身側(cè)響起合呐,我...
    開封第一講書人閱讀 38,964評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎笙以,沒想到半個月后淌实,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,376評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡猖腕,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,592評論 2 333
  • 正文 我和宋清朗相戀三年拆祈,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片倘感。...
    茶點故事閱讀 39,764評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡放坏,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出老玛,到底是詐尸還是另有隱情淤年,我是刑警寧澤,帶...
    沈念sama閱讀 35,460評論 5 344
  • 正文 年R本政府宣布蜡豹,位于F島的核電站互亮,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏余素。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,070評論 3 327
  • 文/蒙蒙 一炊昆、第九天 我趴在偏房一處隱蔽的房頂上張望桨吊。 院中可真熱鬧,春花似錦凤巨、人聲如沸视乐。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,697評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽佑淀。三九已至,卻和暖如春彰檬,著一層夾襖步出監(jiān)牢的瞬間伸刃,已是汗流浹背谎砾。 一陣腳步聲響...
    開封第一講書人閱讀 32,846評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留捧颅,地道東北人景图。 一個月前我還...
    沈念sama閱讀 47,819評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像碉哑,于是被迫代替她去往敵國和親挚币。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,665評論 2 354