2015/04/20

學習的筆記1

變數命名規則:
類別變數、區域變數以駝峰式
常數變數以英文全大寫命名



快捷鍵
Ctrl + R & Ctrl + R (重構 --> 重新命名)
Shift + F12 (尋找所有參考)



//四捨五入的函數,下面為取小數第2位四捨五入
Math.Round(3.115, 2, MidpointRounding.AwayFromZero) //3.12



//C# 會隱含轉換,所以要強制加入
decimal decimalA = 10.1M * 10.23M;
long longA = 12L;
float floatA = 3.14F;



//C# 變數可以小轉大,但不能大轉小,若要大轉小要進行明確轉換
int i = 10;
double d = 10.1;
i = d;//會發生不能隱含轉換
i = (int)d; //進行明確轉換,但會遺失部分的資料



//decimal ToString() 四捨五入用法
deciaml d = 12.345;
Console.WriteLine(d.ToString("N2"));//四捨五入到小數第2位



//利用region可以整理與收合、展開程式碼,讓程式碼較為乾淨
#region 主程式碼

    //some Code

#endregion



//類別變數是被封裝起來的,在程式撰寫時要加上this
public class Person
{
    int age;

    public int Age
    {
        get { return this.age}
        set { this.age = value }
    }
}

沒有留言:

張貼留言