Home > programming, Tutorialz > Simple arrays in C#

Simple arrays in C#

August 21st, 2010 Leave a comment Go to comments

Simple arrays in C#: “

Defining arrays in C# is rather simple, take a look at these examples:

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i <= 100; i++)
            {
                int[] array = { i };
                foreach (int a in array)
                {
                    Console.WriteLine(a);
                }
            }

            for (int i = 0; i < 100; i++)
            {
                int[] array = { i };
                for (int b = 0; b < array.Length; b++)
                {
                    Console.WriteLine(array[b]);
                }
            }

            string[] array2 = { ‘mark’, ‘pete’, ‘john’, ‘mike’, ‘joan’, ‘charles’, ‘robert’ };

            foreach (string i in array2)
            {
                Console.WriteLine(i);
            }

            Console.ReadKey();
        }
    }
}

More information

(Via 8 bits.)

  1. No comments yet.