An
Array which contains one row or one column is known as Dimensional Array
Ex:
A
1
|
9
|
19
|
29
|
39
|
0 1 2 3 4
A
1
|
9
|
19
|
29
|
39
|
Syntax 1:-
DataType [ ] ArrayName
= new DataType [size];
Ex:-int[ ] A=new int[5];
A[0] A=1; A[1]=9; A[2]=19; A[3]=29; A[4]=39;
(OR)
Syntax
2:-
DataType [ ] ArrayName=
new DataType [size]{Initialize Elements};
Ex:-int[ ] A=new int[5]{1,9,19,29,39};
Syntax
3:-
DataType [ ] ArrayName= new DataType [ ]{Initialize Elements};
Ex:-int[ ] A=new int[ ]{1,9,19,29,39};
Example 1:-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
//program
to display the integer array elements using for Loop
namespace CAArrays
{
class SDArrayEx1
{
static
void Main(string[]
args)
{
int[]
A=new int[5]{1,9,19,29,39};
//A[0] = 1; A[1] = 9; A[2] = 19;A[3]=29;A[4]=39;
Console.Write("Elements of array A Are :- ");
for
(int i = 0; i < 5; i++)
Console.Write(A[i]
+ " ");
Console.Read();
}
}
}
|
Output:-
Example 2 :-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
//program
to display the string array elements using for Loop
namespace CAArrays
{
class SDArray2
{
static
void Main()
{
string[
] A = new string[
] { "sampath", "srinivas", "kalpana","padma","lalitha"
};
Console.WriteLine("Elements of string Array Elements are:- ");
for
(int i = 0; i < 5; i++)
{
Console.Write(A[i]
+ "
");
}
Console.ReadLine(
);
}
}
}
|
Output :-
No comments:
Post a Comment