导出 (0) 打印
全部展开
信息
您所需的主题如下所示。但此主题未包含在此库中。

Type.IsPointer 属性

2013/12/13

获取一个值,通过该值指示 Type 是否为指针。

Namespace:  System
程序集:  mscorlib(位于 mscorlib.dll 中)

public bool IsPointer { get; }

属性值

类型: System.Boolean
如果 Type 为一个指针,则为 true;否则为 false

如果当前 Type 表示泛型类型,或泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false

此属性为只读。

下面的示例说明 IsPointer 属性的用法。


using System;
using System.Reflection;
public class MyTypeDelegator : TypeDelegator
{
   public string myElementType = null;
   private Type myType = null;
   public MyTypeDelegator(Type myType)
      : base(myType)
   {
      this.myType = myType;
   }
   // Override Type.HasElementTypeImpl().
   protected override bool HasElementTypeImpl()
   {
      // Determine whether the type is an array.
      if (myType.IsArray)
      {
         myElementType = "array";
         return true;
      }
      // Determine whether the type is a reference.
      if (myType.IsByRef)
      {
         myElementType = "reference";
         return true;
      }
      // Determine whether the type is a pointer.
      if (myType.IsPointer)
      {
         myElementType = "pointer";
         return true;
      }
      // Return false if the type is not a reference, array, or pointer type.
      return false;
   }
}
public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      try
      {
         int myInt = 0;
         int[] myArray = new int[5];
         MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType());
         // Determine whether myType is an array, pointer, reference type.  
         outputBlock.Text += String.Format("\nDetermine whether a variable is an array, pointer, or reference type.\n") + "\n";
         if (myType.HasElementType)
            outputBlock.Text += String.Format("The type of myArray is {0}.", myType.myElementType) + "\n";
         else
            outputBlock.Text += String.Format("myArray is not an array, pointer, or reference type.") + "\n";
         myType = new MyTypeDelegator(myInt.GetType());
         // Determine whether myType is an array, pointer, reference type. 
         if (myType.HasElementType)
            outputBlock.Text += String.Format("The type of myInt is {0}.", myType.myElementType) + "\n";
         else
            outputBlock.Text += String.Format("myInt is not an array, pointer, or reference type.") + "\n";
      }
      catch (Exception e)
      {
         outputBlock.Text += String.Format("Exception: {0}", e.Message) + "\n";
      }
   }
}


Windows Phone OS

受以下版本支持: 8.0, 7.1, 7.0

Windows Phone

显示:
© 2014 Microsoft