当前位置: 首页>>代码示例>>C#>>正文


C# ArrayTypeMismatchException构造函数代码示例

本文整理汇总了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);
      }
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:40,代码来源:ArrayTypeMismatchException

示例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);
      }
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:40,代码来源:ArrayTypeMismatchException

示例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);
         }
      }
}
开发者ID:.NET开发者,项目名称:System,代码行数:37,代码来源:ArrayTypeMismatchException


注:本文中的System.ArrayTypeMismatchException.ArrayTypeMismatchException构造函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。