using System;
namespace Tutorialsrack
{
class Program
{
/* How To Convert String Array To Char Array in C# */
static void Main(string[] args)
{
string[] strArr = { "Tutorials", "Rack" };
// Convert Element1 into Char Array
char[] element1 = strArr[0].ToCharArray();
Console.WriteLine("Original String Array Element 1: {0}", strArr[0]);
Console.WriteLine("Print Element1 To After converting it into Char Array: ");
foreach (var ch in element1)
{
Console.WriteLine(ch);
}
// Convert Element2 into Char Array
Console.WriteLine("\nOriginal String Array Element 2: {0}", strArr[1]);
Console.WriteLine("Print Element2 To After converting it into Char Array: ");
char[] element2 = strArr[1].ToCharArray();
foreach (var ch in element2)
{
Console.WriteLine(ch);
}
//Hit ENTER to exit the program
Console.ReadKey();
}
}
}
using System;
using System.Linq;
namespace Tutorialsrack
{
class Program
{
/* How To Convert String Array To Char Array Using LINQ in C# */
static void Main(string[] args)
{
string[] strArr = { "Tutorials", "Rack" };
// Convert String array into Char array list
var charArrList = strArr.Select(x => x.ToCharArray()).ToList();
// Print the Char Array
for(int i = 0;i<charArrList.Count;i++)
{
Console.WriteLine("\nOriginal String Array Element {0}: {1}", i + 1, strArr[i].ToString());
Console.WriteLine("Print Element {0} To After converting it into Char Array: ",i+1);
foreach (var ch in charArrList[i])
{
Console.WriteLine(ch);
}
}
//Hit ENTER to exit the program
Console.ReadKey();
}
}
}
using System;
using System.Linq;
namespace Tutorialsrack
{
class Program
{
/* How To Convert String Array To Char Array Using LINQ in C# */
static void Main(string[] args)
{
string[] strArr = { "Tutorials", "Rack" };
// Converted all the String array elements into single character array
var charArrList = strArr.SelectMany(s => s).ToArray();
Console.WriteLine("Print Element To After converting it into Char Array: ");
foreach (var ch in charArrList)
{
Console.WriteLine(ch);
}
//Hit ENTER to exit the program
Console.ReadKey();
}
}
}
using System;
using System.Linq;
namespace Tutorialsrack
{
class Program
{
/* How To Convert String Array To Char Array
Using string.Concat() andToCharArray() Method in C# */
static void Main(string[] args)
{
string[] strArr = { "Tutorials", "Rack" };
// Converted all the String array elements into single character array
var charArrList = string.Concat(strArr).ToCharArray();
Console.WriteLine("Print Element To After converting it into Char Array: ");
foreach (var ch in charArrList)
{
Console.WriteLine(ch);
}
//Hit ENTER to exit the program
Console.ReadKey();
}
}
}
Comments