2020-12-08

C# Essential Training: 1 Syntax and Object Oriented Programming(二)

7. constants and enumerators

> const double pi = Math.PI; // PI欄位是double型別

> pi // 3.1415926535897931

但找了找Math類別的PI欄位的定義:

public const double PI = 3.14159265358979323846;

試了一試:

> Math.PI // 3.1415926535897931

> Math.PI == 3.14159265358979323846 // true

> 3.1415926535897931 == 3.14159265358979323846 // true

> string.Format($"{3.14159265358979323846}") // "3.14159265358979"

docs的定義是3.1415926535897931(16位)

執行Console得到的字串是3.14159265358979(14位),


繼承: Object ➡ ValueType ➡ Enum


(未完待續...)

沒有留言:

張貼留言