LoginSignup
0
0

More than 1 year has passed since last update.

C#・自分用のメモ書き

Last updated at Posted at 2021-06-10

C#の標準入力を受け取り、その文字列を配列に格納する方法を探すのに時間がかかっているので備忘録として記す

using System;
class Program
{
    static void Main()
    {
        var line = Console.ReadLine();

        char[] line1 = line.ToCharArray();
        foreach (char a in line1)
        {
            Console.WriteLine(a);
        }

    }
}

標準入力で文字列を受け取った後にToCharArray()メソッドを用いてchar型の1次元配列に変換してる

foreach文にて1要素ずつ表示しているだけ。

てか、Javaだとfor文でforeach書くからC#にforeach文あるの感動

因みに、区切り文字があれば、Split('区切り文字')を用いてstring[]配列に格納もできる

0
0
1

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
0
0