using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
void
Main()
{
try
{
String[] srcArr = { "Sun", "Mon", "Tue", "Thu" };
String[] destArr =
new
String[10];
Console.WriteLine("Initial Array:");
PrintIndexAndValues(srcArr);
Console.WriteLine("Trying to
get
the ConstrainedCopy"
+" of length
is
greater than the number ");
Console.WriteLine("of elements
from
sourceIndex"
+" to the end of sourceArray.");
Console.WriteLine();
Array.ConstrainedCopy(srcArr, 1, destArr, 0, 4);
}
catch
(ArgumentNullException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch
(RankException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch
(ArrayTypeMismatchException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch
(InvalidCastException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch
(ArgumentOutOfRangeException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
catch
(ArgumentException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
}
public
static
void
PrintIndexAndValues(String[] myArr)
{
for
(
int
i = 0; i < myArr.Length; i++) {
Console.WriteLine("{0}", myArr[i]);
}
Console.WriteLine();
}
}