Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
33
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

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

はじめに

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

環境

  • 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();
        }
    }
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
33
Help us understand the problem. What are the problem?