Q:

How to convert a string into character array in C#.Net?

0

How to convert a string into character array in C#.Net?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {

			//string
			string str = "Hello, How are you?";
           
            int i = 0;
			
			//character array declaration
            char[] CH;
			
			//converting string to character array
            CH = str.ToCharArray();

			//printing character array character by character
            for (i = 0; i < CH.Length;i++ )
            {
                Console.Write(CH[i] + "");
            }

            Console.WriteLine();
        }
    }
}

Output

Hello, How are you?

In this program str is a string type variable, Using string.ToCharArray() method we copied the character of string str to CH.

And then, we are getting the length of the character array (CH) using Length property and printing character by character of CH (character array)

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now