Home [C# 筆記] Console
Post
Cancel

[C# 筆記] Console

輸入

1
2
Console.Read(); // 讀入一個字元
Console.ReadLine(); // 讀入一行字串

舉例

輸入字元

1
char c = Convert.ToChar(Console.Read());

輸入字串

1
string s = Console.ReadLine();

輸入整數

1
int n = Convert.ToInt32(Console.ReadLine());

輸出

使用大括弧{0} {1} 佔符位,後面放參數

1
Console.WriteLine("{0} and {1}", x, y); 

使用$”{參數}”

1
Console.WriteLine($"{x} and {y}"); 
This post is licensed under CC BY 4.0 by the author.