C# Type HasElementType

Description

Type HasElementType gets a value indicating whether the current Type encompasses or refers to another type; that is, whether the current Type is an array, a pointer, or is passed by reference.

Syntax

Type.HasElementType has the following syntax.


public bool HasElementType { get; }

Example

The following example returns true or false depending on whether or not the object is an array, a reference type, or a pointer.


using System;/*www .ja  v  a  2 s  . c  o m*/
using System.Reflection;

public class Example
{
    public static void Main()
    {
        int[] nums = {1, 1, 2, 3, 5, 8, 13};
        Type t = nums.GetType();
        Console.WriteLine("HasElementType is '{0}' for array types.", t.HasElementType);

        t = typeof(Example[]);
        Console.WriteLine("HasElementType is '{0}' for array types.", t.HasElementType);

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version