C# Type IsGenericType

Description

Type IsGenericType gets a value indicating whether the current type is a generic type.

Syntax

Type.IsGenericType has the following syntax.


public virtual bool IsGenericType { get; }

Example

The following code example displays the value of the IsGenericType.


//from  w w  w  .ja v a 2s.  c o m

using System;
using System.Reflection;
using System.Collections.Generic;

public class Base<T, U> { }

public class Derived<V> : Base<int, V> { }

public class Test
{
    public static void Main()
    {
        Type derivedType = typeof(Derived<>);
        DisplayGenericTypeInfo(derivedType);

        // Display its open constructed base type.
        DisplayGenericTypeInfo(derivedType.BaseType);
    }

    private static void DisplayGenericTypeInfo(Type t)
    {
        Console.WriteLine(t);

        Console.WriteLine(t.IsGenericTypeDefinition);

        Console.WriteLine(t.IsGenericType);

        Console.WriteLine(t.ContainsGenericParameters);
    }
}

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