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



Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.