string word = "hello"; char[] wordArray = word.ToCharArray(); foreach (char c in wordArray) { Console.WriteLine(c); }
string sentence = "The quick brown fox jumps over the lazy dog."; char[] sentenceArray = sentence.ToCharArray(10, 16); foreach (char c in sentenceArray) { Console.Write(c); }In this example, the string "The quick brown fox jumps over the lazy dog." is converted into a character array using the ToCharArray method with parameters. The method call specifies that only the characters from position 10 (the letter "b" in "brown") to position 16 (the letter "p" in "jumps") should be converted to a character array. Finally, the resulting array is printed to the console using a foreach loop. The System.ToCharArray method is part of the base class library of .NET Framework.