Methods with Array object
1.
CopyTo(Destination Array, int Index)
This method is used to copy element of
one Array to another Array.
2.Min(
)
This Method will return least value from
the Array.
3.Max(
)
This method will return the maximum
value from the Array.
4.Sum(
)
This method will return the sum of the
elements from the Array.
5.Average(
)
This method will return the sum of the elements from
the Array.
Properties with Array object
1.Length
This properties returns size of the
Array .
2.Rank
This
property returns the number of dimensions present within the Array.
Example:
-
Consider
To Arrays A& B
B
10
|
20
|
30
|
40
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0 1 2 3
4 5 6 7 8 9
10
1)
A.CopyTo(B,0)
1
|
9
|
19
|
29
|
39
|
0
|
0
|
0
|
0
|
0
|
0
|
0 1 2 3
4 5 6 7 8 9
10
A.CopyTo(B,3)
25
|
15
|
35
|
1
|
9
|
19
|
29
|
39
|
0
|
0
|
0
|
0 1 2 3
4 5 6 7 8 9
10
A.CopyTo(B,9) -- Raises Run time Error
2)A.Min(
) -- 1
3)A.Max(
) -- 39
4)A.Sum(
) -- 97
5)A.Average(
) -- 19.4
Properties
1)A.Length -- 5
2)A.Rank
-- 1
Example:-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CAArrays
{
class ArrayObj
{
static
void Main()
{
int[]
A = new int[5]
{1,9,19,29,39};
int[]
B = new int[11]
{10,20,30,40,0,0,0,0,0,0,0};
Console.WriteLine("Rank of Array A is:- "+A.Rank);
Console.WriteLine("Rank Array B isv:- "+B.Rank);
Console.WriteLine("Length of Array A is:- "+A.Length);
Console.WriteLine("Length of Array B is:- "+B.Length);
Console.WriteLine("Number of Elements in Array A Are:- " + A.Count());
Console.WriteLine("Least value in Array A is:- " +A.Min());
Console.WriteLine("Heighest value Array A is:- " +A.Max());
Console.WriteLine("Sum of Elements in Array A is:- " + A.Sum());
Console.WriteLine("Average of Elements in Array A is:- " +A.Average());
Console.WriteLine("Number of Elements in Array A Are:- " +A.Count());
Console.WriteLine("Elements of Array A Are :- ");
foreach
(int i in A)
{
Console.Write(i+" ");
}
Console.WriteLine("\nElements of Array B Are :-");
foreach
(int i in B)
{
Console.Write(i+" ");
}
Console.WriteLine("\nElements of Array B After Copying:-");
foreach
(int i in B)
{
Console.Write(i+" ");
}
Console.ReadLine();
}
}
}
|
Output:-
No comments:
Post a Comment