Array

In computer memory every byte is an array element. Abstractions translate these bytes into objects and give them meaning. Arrays are a foundational type. They are the basis of more usable collections. They use a special syntax form.

An array is a fixed collection of same-type data that are stored contiguously and that are accessible by an index.

Example:
We allocate and provide integers to three different values such as 2 , 2*2 and 4*3 respectively.

Programming:

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 WindowsFormsApplication3
 {
     public partial class Form1 : Form
     {
         public Form1()
         {
             InitializeComponent();
         }

         private void button1_Click(object sender, EventArgs e)
         {
             int[] values = new int[3];
             values[0] = 2;
             values[1] = values[0] * 2;
             values[2] = values[1] * 3;

             foreach (int value in values)
             {
              MessageBox.Show(value.ToString());
             }
         }
     }
 }

Result:
Output in Message box  =  2
Output in Message box = 4
Output in Message box = 12

No comments:

Post a Comment