One-Dimensional array in C# with Example

One-dimensional arrays are the simplest form of arrays. These types of arrays are used to store number of items of a predefined type. All items in a single dimension array are stored in a row starting from 0 to the size of array - 1.


Single Dimensional array is also called one-dimensional array.

Declaration of one dimensional array :

int[] intArr  = new int[5]; This array contains the elements from intArr[0] to intArr[4]

string[] strArr  = new string[6];

Example : The below code will return the rupees in word format from numeric.[below 1000 only]


C# CODE

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _1D_ArrayApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] Ones = new string[] { "One",
 "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen"};
            string[] Tens = new string[] { "Ten",
"Twenty", "Thirty", "Fourty", *
"Fifty", "Sixty", "Seventy",
"Eighty", "Ninety" };
            string Result = "";
            int i, n;
            n = int.Parse(textBox1.Text);
            if (n > 99 && n < 1000)
            {
                i = n / 100;
                Result = Ones[i - 1] + " " + "Hunred And";
                n = n % 100;
            }
            if (n > 19 && n < 100)
            {
                i = n / 10;
                Result =Result + Tens[i - 1]+" ";
                n = n % 10;
            }
            if (n >0 && n <20 o:p="">
            {
                i = n / 1;
                Result = Result + Ones[i - 1] + " "+"Rupees Only";
                n = n % 1;
            }
            textBox2.Text = Result;
        }
    }
}
  

 [ Windows application code with C#]