Professional Documents
Culture Documents
Value Type:
Num2
50
int Num2; Variable Declaration
Num2=Num1; Initializing Num2 with Num1
Describing Memory Allocation (Contd.)
Num1
New Value Assigned to Num1 Num1=60;
60
Reference Type:
10
Mercedes
Referring to Memory
***
Location Where the Data
is Stored
Using Structure
Index Index
Value 0 Value 6
Declaring an Array
int[ ] Score; []
Is used to specify the
rank of the array
Declaring an Array (Contd.)
In C#, you can initialize the array variable and can assign
values to the array elements. In addition, you can copy the
array variable to another variable.
During initialization, you need to use the new keyword to
create an instance of the array. In addition, the size of the
array is also specified while it is initialized.
The following is an example of array initialization:
int[] Score; // Array declaration
Score = new int[10]; //Array Instance
Initializing and Assigning Values to Array (Contd.)
Problem Statement:
David, a student of California University, is currently pursuing
mathematics. He is working on a project named Matrix
Subtraction. He needs to perform the following tasks for his
project:
Accept data in two Arrays.
Perform the subtraction operation.
Verify the value of subtraction.
Help David to create the C# program using Visual Studio IDE.
Demo: Matrix Subtraction Using Arrays (Contd.)
Solution:
To solve the preceding problem, David needs to perform the
following tasks:
1. Create a console-based application for Matrix Subtraction.
2. Build and execute an application.
Multidimensional Arrays
0 1 2 3 4 1
0 1 2 3 4
Multidimensional Arrays (Contd.)
The Array class is the base class for all the arrays in C#.
The Array class provides properties and methods to work
with arrays.
Properties: The following table explains some of the most
commonly used properties of the Array class.
Properties Explanation
Properties Explanation
Sort Performs sort operation on an array passed to it as a parameter
Clear Removes all items of an array and sets a range of items in the
array to 0
GetLength Returns the number of items in an Array
GetValue Returns the value of the specified item in an Array
IndexOf Returns the index of the first occurrence of a value in a
one-dimensional Array or in a portion of the Array
Summary