本文整理汇总了C#中System.ArrayTypeMismatchException.ArrayTypeMismatchException构造函数的典型用法代码示例。如果您正苦于以下问题:C# ArrayTypeMismatchException构造函数的具体用法?C# ArrayTypeMismatchException怎么用?C# ArrayTypeMismatchException使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在类System.ArrayTypeMismatchException
的用法示例。
在下文中一共展示了ArrayTypeMismatchException构造函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyArray
//引入命名空间
using System;
public class ArrayTypeMisMatchConst
{
public void CopyArray(Array myArray,Array myArray1)
{
string typeArray1 = myArray.GetType().ToString();
string typeArray2 = myArray1.GetType().ToString();
// Check whether the two arrays are of same type or not.
if(typeArray1==typeArray2)
{
// Copy the values from one array to another.
myArray.SetValue("Name: "+myArray1.GetValue(0),0);
myArray.SetValue("Name: "+myArray1.GetValue(1),1);
}
else
{
// Throw an exception of type 'ArrayTypeMismatchException'.
throw new ArrayTypeMismatchException();
}
}
static void Main()
{
try
{
string[] myStringArray = new string[2];
myStringArray.SetValue("Jones",0);
myStringArray.SetValue("John",1);
int[] myIntArray = new int[2];
ArrayTypeMisMatchConst myArrayType = new ArrayTypeMisMatchConst();
myArrayType.CopyArray(myStringArray,myIntArray);
}
catch(ArrayTypeMismatchException e)
{
Console.WriteLine("The Exception is :"+e);
}
}
}
示例2: CopyArray
//引入命名空间
using System;
public class ArrayTypeMisMatchConst
{
public void CopyArray(Array myArray,Array myArray1)
{
string typeArray1 = myArray.GetType().ToString();
string typeArray2 = myArray1.GetType().ToString();
// Check whether the two arrays are of same type or not.
if(typeArray1==typeArray2)
{
// Copies the values from one array to another.
myArray.SetValue("Name: "+myArray1.GetValue(0),0);
myArray.SetValue("Name: "+myArray1.GetValue(1),1);
}
else
{
// Throw an exception of type 'ArrayTypeMismatchException' with a message string as parameter.
throw new ArrayTypeMismatchException("The Source and destination arrays are not of same type.");
}
}
static void Main()
{
try
{
string[] myStringArray = new string[2];
myStringArray.SetValue("Jones",0);
myStringArray.SetValue("John",1);
int[] myIntArray = new int[2];
ArrayTypeMisMatchConst myArrayType = new ArrayTypeMisMatchConst();
myArrayType.CopyArray(myStringArray,myIntArray);
}
catch(ArrayTypeMismatchException e)
{
Console.WriteLine("The Exception Message is : " + e.Message);
}
}
}
示例3: CopyArray
//引入命名空间
using System;
public class ArrayTypeMisMatchConst
{
public void CopyArray(Array myArray,Array myArray1)
{
try
{
// Copies the value of one array into another array.
myArray.SetValue(myArray1.GetValue(0),0);
myArray.SetValue(myArray1.GetValue(1),1);
}
catch(Exception e)
{
// Throw an exception of with a message and innerexception.
throw new ArrayTypeMismatchException("The Source and destination arrays are of not same type.", e);
}
}
static void Main()
{
try
{
string[] myStringArray = new string[2];
myStringArray.SetValue("Jones",0);
myStringArray.SetValue("John",1);
int[] myIntArray = new int[2];
ArrayTypeMisMatchConst myArrayType = new ArrayTypeMisMatchConst();
myArrayType.CopyArray(myStringArray,myIntArray);
}
catch(ArrayTypeMismatchException e)
{
Console.WriteLine("The Exception Message is : "+e.Message);
Console.WriteLine("The Inner exception is :"+e.InnerException);
}
}
}