[Solved] Item type from a list type c# [closed]


Based on my understanding you want to check if the type is a list and if the list’s elements is type X.

You can do the following:

        var type = (new List<int>()).GetType();

        if (type.GetInterface("IList") != null && type.IsGenericType
                && type.GenericTypeArguments.Length == 1
                && type.GenericTypeArguments[0] == typeof(int))
                    Console.WriteLine(true); //Outputs True

3

solved Item type from a list type c# [closed]