Basic review------use of variables and constants

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


namespace 第三章
{
    class Program
    {
        enum Mydate   //日期枚举
        {
            Sun = 0,
            Mon = 1,
            Tue = 2,
            Wed = 3,
            Thi = 4,
            Fri = 5,
            Sat = 6


        }


        class C
        {
            private int _value;


            public int Value
            {
                get { return _value; }
                set { _value = value; }
            }




        }
        static void Main(string[] args)
        {
            # region variable definition assignment
            // definition of variable, assignment
            int a;
            string b;
            int c = 0;
            string d = "Duan Bin" ;
            // Colleagues define multiple variables and assign values
            ​​int e, f, g;
            string h, m, k;
            string l = "Duan Bin", o = "Duan Bin", n = "Duan Bin";
            string p;


            / /Assign a variable to a variable, which must be an assigned variable
            b = l;
            #endregion


            #region variable domain
            //for loop, the variable scope is only within the loop body
            for (int i = 0; i <= 20; i++)
            {


                Console.WriteLine(i.ToString());
            }
            Console.ReadLine();
            #endregion


            #region variable Type


            /*
             *---------------------------
             * Value type
             * ------------------- ---
             */
            int ls = 997;
            byte test = 255;
            Console.WriteLine("ls={0}", ls);
            Console.WriteLine("test={0}", test);
            Console.ReadLine() ;


            //Force conversion
            float fl = 3.14F;
            double db = 3.14;
            double dbTest = 32d;
            fl = (float)db;


            bool tr = true;








            /*
           * --------------- -------
           * Reference type
           * -----------------------
           */
            int v1 = 0;
            int v2 = v1;
            v2 = 927;
            C r1 = new C();
            C r2 = r1;
            //C r2 = new C();
            r2.Value = 112;
            Console.WriteLine("Value:{0},{1}", v1, v2);
            Console.WriteLine("Refs:{0},{1}", r1.Value, r2.Value);
            Console.ReadLine();


            #endregion


            #region Use of enumeration
            int toDay = (int)DateTime.Now.DayOfWeek ; //Get the day of the week
            switch (toDay)
            {
                case (int)Mydate.Sun:
                    {
                        Console.WriteLine("Today's Sunday");
                        break;
                    }
                case (int)Mydate.Mon:
                    {
                        Console.WriteLine("Today's Monday" ");
                        break;
                    }
                case (int)Mydate.Tue:
                    {
                        Console.WriteLine("Today's Tuesday");
                        break;
                    }
                case (int)Mydate.Wed:
                    {
                        Console.WriteLine("Today's Wednesday");
                        break;
                    }
                case (int)Mydate. Thi:
                    {
                        Console.WriteLine("Today is Thursday");
                        break;
                    }
                case (int)Mydate.Fri:
                    {
                        Console.WriteLine("Today is Friday");
                        break;
                    }
                case (int)Mydate.Sat:
                    {
                        Console.WriteLine("Today is Saturday");
                        break;
                    }


                default:
                    {
                        break;
                    }


            }
            Console.ReadLine();
            #endregion


            #region data type conversion
            double x = 19810927.8112;
            int y = (int)x;//force explicit conversion


            int zhuanB = 312;
            double zhuanD = zhuanB; //Implicit conversion
            
            Console.WriteLine(y);
            Console.ReadLine();


            //Boxing, value type is implicitly converted to reference type
            int zhuanI = 2008;
            object obj = zhuanI ;
            Console.WriteLine("1 The value of zhuanI is {0}, and the boxed object is {1}", zhuanI, obj);//2008,2008
            zhuanI = 927;
            Console.WriteLine("2 The value of zhuanI is {0}, the boxed object is {1}", zhuanI, obj);//927,2008
            //Unboxing, the reference type is cast to the value type
            int zhuanX=(int)obj;
            Console.WriteLine(" Unboxing: The object is: {0}, the value is {1}",obj,zhuanX);
            Console.ReadLine();
            #endregion


            #region The use of constants
            const double doublePI=3.1415926;//Constants must be initialized and assigned, and cannot be modified


            Console.WriteLine(doublePI);


            #endregion


        }


























    }
}

Guess you like

Origin blog.csdn.net/u014156887/article/details/37873427