LoginSignup
42
37

More than 5 years have passed since last update.

【備忘録】char配列⇔string型の変換

Last updated at Posted at 2015-02-28

はじめに

この手の変換ってよく忘れちゃうので、明日の自分のためにメモっとく。

環境

  • Windows7 Professional SP1
  • Microsoft Visual Studio Version 12.0.31101.00 Update 4
  • Microsoft .NET Framework Version 4.5.51209
  • Microsoft Visual C# 2013

Example

    /// <summary>
    /// 【備忘録】char配列⇔string型の変換
    /// </summary>
    class CharArray01
    {
        private static char[] c;
        private static string s;

        static void Main(string[] args)
        {
            // char配列をstring型へ変換
            c = new char[] { 'A', 'B', 'C' };
            // s = "ABC"
            s = new String(c);

            // string型をchar配列へ変換
            s = "ABC";
            // c[0]='A', c[1]='B', c[2]='C'
            c = s.ToCharArray();

            Console.ReadKey();
        }
    }
42
37
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
42
37