C# generic list how to get the type of T? [duplicate]

Type type = pi.PropertyType; if(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) { Type itemType = type.GetGenericArguments()[0]; // use this… } More generally, to support any IList<T>, you need to check the interfaces: foreach (Type interfaceType in type.GetInterfaces()) { if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IList<>)) { Type itemType = type.GetGenericArguments()[0]; // do something… break; } }

Randomize a List

Shuffle any (I)List with an extension method based on the Fisher-Yates shuffle: private static Random rng = new Random(); public static void Shuffle<T>(this IList<T> list) { int n = list.Count; while (n > 1) { n–; int k = rng.Next(n + 1); T value = list[k]; list[k] = list[n]; list[n] = value; } } Usage: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)