C# Two Dimensional Array Sample | 2D Array in C#

using System;

namespace ClassRoomSamples
{
    class Demo05Array2D
    {
        static void Main(string[] args)
        {
            //Object initializer syntex....
            int[ , ] Marks = new int[5, 2] {{ 72, 20 },{ 70, 21},
   { 60, 15 },{ 73, 16 },{ 64, 18 }};

            Console.WriteLine($"{"Student",-12}{"Internal",10}                                                           {"External",10}");
            Console.WriteLine("===================================");
            for (int student = 0; student < 5; student++)
            {
  //student - 0,1,2,3,4
  Console.Write($"Student{student + 1:00}");
                for (int sub = 0; sub < 2; sub++)
                {
                    Console.Write($"{Marks[student, sub],10}");
                }
                Console.WriteLine();
            }
            Console.WriteLine("===================================");
            Console.ReadKey();
        }
    }
}



Output

Student       Internal  External
===================================
Student01        72        20
Student02        70        21
Student03        60        15
Student04        73        16
Student05        64        18
===================================


No comments:

Post a Comment