using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
void
Main()
{
try
{
int
[] myArr = {10, 20, 30, 40};
Console.WriteLine(
"Array Before Operation:"
);
PrintIndexAndValues(myArr);
Console.WriteLine();
Console.WriteLine(
"Taking index out of bound:"
);
Array.Clear(myArr, -1, 2);
Console.WriteLine(
"Array After Operation:"
);
PrintIndexAndValues(myArr);
}
catch
(ArgumentNullException e) {
Console.Write(
"Exception Thrown :"
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
catch
(IndexOutOfRangeException e) {
Console.Write(
"Exception Thrown :"
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
}
public
static
void
PrintIndexAndValues(
int
[] myArr)
{
for
(
int
i = 0; i < myArr.Length; i++) {
Console.WriteLine(
"{0}"
, myArr[i]);
}
}
}