One Dimensional Array in C#

In this chapter you will learn:
  • What is single dimensional array?
  • How to declare one dimensional array?
  • How to use single dimensional array in C# programming?

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 (“[]”). To declare single dimensional array in C#, you can write the following code.

string[] Books = new string[5];

The array age is a one dimensional array that contains only 5 elements in a single row.  

Programming Example of One Dimensional Array:

onedimensional-array-flowchart
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace One_Dimensional_Array
{
    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("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


All the element of Books array is:

1       2        3              4        5
C#    Java    VB.NET    C++    C
__

Summary

In this chapter you learned about single dimensional array in C#. You also learned how to store value and access value from single dimensional array. In next chapter you will learn about multi dimensional array in C#.

More Examples

Write A Program To Print One Dimensional Array In Reverse Order
Write A Program To Sort One Dimensional Array In Descending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Desending Order Static Class Array Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Non Static Method.
Write A Program To Sort One Dimensional Array In Ascending Order Using Static Method.
Write A Program To Add The Diagonal Of Two-Dimensional Array.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.