LoginSignup
1
1

More than 5 years have passed since last update.

文字列を連結させるプログラム C#

Posted at

初めに

このブログでは、授業で習ったことや自分で勉強したことなどをまとめて記事にしています。

今回は文字列を連結させるプログラムを作成しました。

ソースコード

Program.cs

    class Program
    {
        static void Main(string[] args)
        {
            string str_1 = "今日の晩は";
            string str_2 = "夜勤なのでサボりたい";

            StringBuilder sb = new StringBuilder();
            sb.Append(str_1);
            sb.Append(str_2);

            string result = sb.ToString();

            Console.WriteLine(result);

            Console.ReadKey();
        }
    }

▼実行結果
f15.png
StringBuilderの中に、sb.appendでstr_1とstr_2を入れて連結させています。
ちなみに、sb.clear()にすれば現在sbに入っている値をすべて削除出来ます。


最後まで読んでくれてありがとうございました!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1