Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ String | データ型の取り扱い
/
C#の基礎

bookString

メニューを表示するにはスワイプしてください

string は文字の並び。文字列データの保存に使用。

main.cs

main.cs

copy
12345678910111213
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "Hello, World!"; Console.WriteLine(text); // Output: Hello, World! } } }

文字列データ(テキスト)は常に二重引用符(")で囲む。

文字列には算術演算はできないが、プラス(+)演算子で2つの文字列を結合可能。この処理は文字列連結と呼ばれる。

main.cs

main.cs

copy
123456789101112131415
using 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

main.cs

copy
12345678910111213
using 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

main.cs

copy
12345678910111213
using 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); } } }
question mark

次のコードの出力は何ですか?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 2.  6

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 2.  6
some-alt