How to

get generic arguments of generic class

Published: 13. December 2008 | Updated: 13. December 2008
License: Microsoft Public License (MS-PL)
Categories: Framework » Generics
Tags: C# Generics Reflection
Was this snippet helpful for you? YESYES / NONO

Snippet example shows how to get generic arguments of generic class

Import namespaces

using System.Collections.Generic;

Code

Dictionary<int, string> dictionary = new Dictionary<int, string>();
Type type = dictionary.GetType();
Type[] arguments = type.GetGenericArguments();

foreach (Type argument in arguments)
{
    Console.WriteLine(argument);
}
Console Output:
System.Int32
System.String
Send us feedback about this snippet »



Related Snippets: