ListmyList = new List (); Type elementType = myList.GetType().GetTypeInfo().GenericTypeArguments[0]; Console.WriteLine(elementType.Name);
int[] myNumbers = { 1, 2, 3, 4, 5 }; var evenNumbers = from n in myNumbers where n % 2 == 0 select n; Type elementType = evenNumbers.GetType().GetTypeInfo().GenericTypeArguments[0]; Console.WriteLine(elementType.Name);In this example, we create an array of integers and use a LINQ query to select only even numbers. We then retrieve the ElementType of the resulting collection using `GetTypeInfo()`. This code belongs to the System.Linq package library. Overall, ElementType is a useful class for working with collections and performing type-specific operations on their elements.