Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Reading characters in a string using foreach in C#

The following code converts the string to char array then uses the foreach loop for reading the characters.
  1. using System;
  2. using System.IO;
  3.  
  4. public class ForgetCode
  5. {
  6. public static void Main()
  7. {
  8. string str = "Coming from Forget Code";
  9. char[] b = new char[str.Length];
  10.  
  11. b = str.ToCharArray();
  12.  
  13. foreach (char c in b)
  14. {
  15. Console.Write(c);
  16. }
  17. }
  18. }

Output:
Coming from Forget Code