IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
Array & Exception Handling in C# (CSharp)
1. Presentation Topic:
Array & Exception Handling in C#
Name :Md. Sihab Uddin
Batch : 6th
Semester : 8th
ID. : 00616306005
Pundra University of Science & Technology
Computer Science & Engineering
7/2/2020 1Array & Exception Handling in C#
2. Arrays
• An array is a group of like-typed variables that are referred to
by a common name.
• The data types of the elements may be any valid data type like
char, int, float, etc.
• The elements are stored in a contiguous location.
• Length of the array specifies the number of elements present in
the array.
• The variables in the array are ordered and each has an index
beginning from 0.
7/2/2020 Array & Exception Handling in C# 2
3. Arrays(cont…)
• The following figure shows how array stores values
sequentially :
7/2/2020 Array & Exception Handling in C# 3
4. Array Declaration
• Syntax :
< Data Type > [ ] < Array_Name >
• Here:
< Data Type > : It define the element type of the array.
[ ] : It define the size of the array.
< Array_Name > : It is the Name of array.
• Example :
int[] x;
string[] s;
• Note :
Only Declaration of an array doesn’t allocate memory to the
array. For that array must be initialized.
7/2/2020 Array & Exception Handling in C# 4
5. Array Initialization
• Syntax :
type [ ] < Name_Array > = new < data_type > [size];
• Here:
type specifies the type of data being allocated,
size specifies the number of elements in the array,
Name_Array is the name of array variable.
new will allocate memory to an array according to its size.
7/2/2020 Array & Exception Handling in C# 5
6. Array Initialization(cont…)
To Show Different ways for the Array Declaration and
Initialization:
• Example 1 :
– defining array with size 5. But not assigns values
– int[] intArray1 = new int[5];
• Example 2 :
– defining array with size 5 and assigning values at the same time
– int[] intArray2 = new int[5]{1, 2, 3, 4, 5};
• Example 3 :
– defining array with 5 elements which indicates the size of an array
– int[] intArray3 = {1, 2, 3, 4, 5};
7/2/2020 Array & Exception Handling in C# 6
9. One Dimensional Array
• In this array contains only one row for storing the values. All
values of this array are stored contiguously starting from 0 to
the array size. For example, declaring a single-dimensional
array of 5 integers :
• Syntax :
type [ ] < Array_Name> = new < data_type > [size];
• Example:
int[ ] array_int = new int[5];
7/2/2020 Array & Exception Handling in C# 9
10. Multidimensional Arrays
• The multi-dimensional array contains more than one row to
store the values.
• It is also known as a Rectangular Array in C# because it’s
each row length is same.
• It can be a 2D-array or 3D-array or more.
• To storing and accessing the values of the array, one required
the nested loop.
7/2/2020 Array & Exception Handling in C# 10
11. Multidimensional Arrays(cont…)
• The multi-dimensional array declaration, initialization and
accessing is as follows :
• Syntax :
Creates a two-dimensional array of four rows and two
columns.
int[ , ] intarray = new int[4, 2];
Creates an array of three dimensions, 4, 2, and 3
int[ , , ] intarray1 = new int[4, 2, 3];
7/2/2020 Array & Exception Handling in C# 11
12. Exception
• Exceptions are unusual error conditions that occur during
execution of a program or an application.
• An exception is an unwanted or unexpected event, which
occurs during the execution of a program i.e at runtime, that
disrupts the normal flow of the program’s instructions.
7/2/2020 Array & Exception Handling in C# 12
13. Exception Handling
C# exception handling is built upon four keywords:
• try − A try block identifies a block of code for which particular
exceptions is activated. It is followed by one or more catch
blocks.
• catch − A program catches an exception with an exception
handler at the place in a program where you want to handle the
problem.
• finally − The finally block is used to execute a given set of
statements.
• throw − A program throws an exception when a problem shows
up. This is done using a throw keyword.
7/2/2020 Array & Exception Handling in C# 13