s

C# single dimensional array edit button Edit

author
Rakesh Kumar Sutar | calendar 20 January 2021 | 1978

Introduction

The one dimensional array or single dimensional array in C# is the simplest type of array that contains only one row for storing data. It has single set of square bracket (“[]”). The no. of array count starts from 0 to n.

Syntax

data type[ ] array_name = new data type[No. of array required]

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World
{
    
    class Program
    {
        
        static void Main(String[] args)
        {
            //Declaring single dimensional array
            string[] Books = new string[5];
            Books[0] = "C#";
            Books[1] = "Java";
            Books[2] = "VB.NET";
            Books[3] = "C  ";
            Books[4] = "C";

            Console.WriteLine("\t" "All the element of Books array is:\n\n");

            int i = 0;
            //Formatting Output
            Console.Write("\t1\t2\t3\t4\t5\n\n\t");
            for (i = 0; i < 5; i  )
            {
                Console.Write("{0}\t", Books[i]);
            }
            Console.ReadLine();
        }
    }
}

Output