String
メニューを表示するにはスワイプしてください
string は文字の並び。文字列データの保存に使用。
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "Hello, World!"; Console.WriteLine(text); // Output: Hello, World! } } }
文字列データ(テキスト)は常に二重引用符(")で囲む。
文字列には算術演算はできないが、プラス(+)演算子で2つの文字列を結合可能。この処理は文字列連結と呼ばれる。
main.cs
123456789101112131415using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string partOne = "The first sentence. "; string partTwo = "The second sentence."; string combined = partOne + partTwo; Console.WriteLine(combined); // Output: The first sentence. The second sentence. } } }
文字列データ内で改行を表すには、改行文字(\n)を使用。
次の例を参照。
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\nThe second line."; Console.WriteLine(text); } } }
\n 文字が現れると、テキストは自動的に新しい行に移動します。複数の改行文字を使うことで、複数行を飛ばすことができます。
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\n\n\nThe second line.\nThe third line."; Console.WriteLine(text); } } }
すべて明確でしたか?
フィードバックありがとうございます!
セクション 2. 章 6
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 2. 章 6