Hi,
In order to access all the items of an array in C#, use the following lines of code. We are using foreach loop to access all the elements of an array in C#.
using System; class MainClass { public static void Main() { string myString = "Apple Ball Cat" ; char [] separator = { ' ' }; string [] spellArr= myString .Split(separator); foreach ( object chk in spellArr) Console.WriteLine( "Spell: {0}" , chk ); } } |
It will print out,
Spell: Apple
Spell: Ball
Spell: Cat