What is the best way to create the matrix C?
string A;
char[] B = A.ToCharArray();
string[] C = new string[B.Length];
for (int i = 0; i < B.Length ; i++)
{
C[i] = B[i].ToString();
}
What is the best way to create the matrix C?
string A;
char[] B = A.ToCharArray();
string[] C = new string[B.Length];
for (int i = 0; i < B.Length ; i++)
{
C[i] = B[i].ToString();
}
You just want a nicer way to do what you're doing? I suppose you could do it like this:
string A = "ABCDEFG";
string[] C = A.Select(c => c.ToString()).ToArray();
Another option as well as mquander's is to use Array.ConvertAll():
string[] C = Array.ConvertAll(A.ToCharArray(), c => c.ToString());
I generally prefer the LINQ approach, but ConvertAll is worth knowing about (for both arrays and lists) as it's able to use the fact that it knows the size to start with.
using System.Text.RegularExpressions;
string[] chars = Regex.Split(s, string.Empty);