Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,982 answers

573 users

How to convert string to char array in C#

2 Answers

0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        string s = "c# java c++";
 
        char[] array = s.ToCharArray();
 
        for (int i = 0; i < array.Length; i++) {
            Console.WriteLine(array[i]);
        }
    }
}



/*
run:
   
c
#
 
j
a
v
a
 
c
+
+
  
*/

 



answered Jan 9, 2017 by avibootz
edited Apr 11, 2024 by avibootz
0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        try {
            string s = "Let's StartUP";
            char[] char_arr = s.ToCharArray();
 
            for (int i = 0; i < char_arr.Length; i++) {
                Console.WriteLine("char_arr[{0}] = {1}", i, char_arr[i]);
            }
        }
        catch (Exception ex) {
            Console.WriteLine(ex.Message);
        }
    }
}


 
/*
run:
   
char_arr[0] = L
char_arr[1] = e
char_arr[2] = t
char_arr[3] = '
char_arr[4] = s
char_arr[5] =
char_arr[6] = S
char_arr[7] = t
char_arr[8] = a
char_arr[9] = r
char_arr[10] = t
char_arr[11] = U
char_arr[12] = P
  
*/

 



answered Apr 11, 2024 by avibootz

Related questions

2 answers 167 views
167 views asked Jan 10, 2017 by avibootz
1 answer 91 views
1 answer 109 views
1 answer 139 views
139 views asked Jan 21, 2021 by avibootz
1 answer 144 views
1 answer 120 views
1 answer 190 views
190 views asked Jun 3, 2014 by avibootz
...