C#学习小记

namespace Test
{

class Stamp
{
    public enum Genders
    {
        Male,
        Female
    }

    public string Name { get; set; }
    public int Age { get; set; }

    private Genders gender;
    public Genders Gender
    {
        get { return gender; }
        set { gender = value; }

    }
}

static class ReferenceAndValue
{
    public static void ShowInfo()
    {
        Stamp stamp1 = new Stamp { Name = "MR", Age = 20 };
        Stamp stamp2 = new Stamp { Name = "MJ", Age = 25 };

        int age = stamp1.Age;
        stamp1.Age = 30;
        Stamp stamp3 = stamp2;
        stamp2.Name = "MRKJ";
        Console.WriteLine("stame1的Age:" + stamp1.Age);
        Console.WriteLine("age is:" + age);
        Console.WriteLine("stamp2  name is" + stamp2.Name);
        Console.WriteLine("stamp3 name is" + stamp3.Name);

        Console.WriteLine("stamp2 age is" + stamp2.Age);
        Console.WriteLine("stamp1 age is" + stamp1.Age);
    }
}

public enum Mrkj
{
    CS = 1,
    Java = 2,
    C = 3
}


class Program
{
    /*
    readonly int roValue = 10;
       
    public Program()
    {
        roValue = 20;
    }
    */

    string name = "name asdf";
    static string company = "asdfdafdsafdasfdsafad";

    static void Main(string[] args)
    {
        /*
        Console.WriteLine(company);
        Program pro = new Program();
        Console.WriteLine(pro.name);
        */

        /*
        Console.Write("Hello World");
        Console.WriteLine();

        const double PI = 3.14;

        Program pro = new Program();
        Console.WriteLine(pro.roValue);
        Console.WriteLine();

        double first = 432.234;
        Console.WriteLine(first);
        int temp = (int)first;
        int temp2 = Convert.ToInt32(first); 
        //int firstInt = Int32.Parse(first.ToString());//wrong
        int tempInt = Int32.Parse(temp.ToString());//right

        Console.WriteLine(tempInt);

        int rise = 2;
        double second;
        second = Double.Parse((first * rise).ToString());

        string str = "10";
        int relust = Int32.Parse(str);
        double db = Double.Parse(str);

        //Console.WriteLine(db);
        Console.WriteLine(relust);
        */


        /*
        ReferenceAndValue.ShowInfo();
        */


        /*
        Console.WriteLine((int)Mrkj.CS);
        */

        /*
        Stamp stmp = new Stamp();
        stmp.Gender = Stamp.Genders.Male;  
        */

        /*
        int i = 7;
        int j = 6;
        int result1 = i & j;//按位与
        int result2 = i | j;//按位或
        int result3 = ~i; // 按位取反
        int result4 = i <<3;//左移3位  ==   将原始值 * 2的3次方
        int result5 = j >>4;//右移4位  ==   将原始值 / 2的4次方
        */

        /*
        //is 运算符  同isKindOf
        int i = 10;
        bool result = i is string;

        Console.WriteLine("请输入一个年份:");
        int year = Convert.ToInt32(Console.ReadLine());
        bool isleapyear = (year % 400 == 0) || ((year % 4 == 0) && (year % 100) == 0);
        */


        /*
        // typeOf() 获取原型对象类型
        Type intType = typeof(int);
        Console.WriteLine(intType);
        */


        /*
        int x = 24;
        //x += x-- += x %= 17;
        //应该改为
        x += x--;
        x += x %= 17;

        // += 符号的左边 必须是变量
        */


        /*
        string name = "张三";  
        char sex = '男';

        // char 同Char 一样, 并且只能用单引号、单个的字符
        */

        //\n 回车换行
        //\t 横向跳到下一个制表符位置
        //\" 双引号
        //\b 退格
        //\r 回车
        //\f 换页
        //\\ 反斜杠
        //\' 单引号符
        
        
        /*
        Console.WriteLine("C:\\Users\\Public\\Documents\\Tencent\\QQ");
        Console.WriteLine(@"C:\Users\Public\Documents\Tencent\QQ");//两者相同
        */


        Console.ReadLine();
    }
}

}

你可能感兴趣的:(C#学习小记)