當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。