By casting the items in a sequence to a certain type, the LINQ Cast method can be used to change the type of the sequence's elements. A series of one type is passed to the Cast method, which returns a new sequence of another kind with each element cast to the desired type.   Here is an illustration of how to cast a sequence of object elements into a sequence of string elements using the Cast method:  object[] objects = ...
var strings = objects.Cast();  In this illustration, the objects array is given a call to the Cast method, and the elements are converted to string type. Each element is cast from the object type to the string type in the new sequence of string elements that the Cast function returns.   Note that if any element in the input sequence cannot be cast to the desired type, the Cast method will throw an exception. Use the OfType method to filter the sequence and maintain just the components that can be cast to the desired type if you want to avoid this.   Here's an illustration of how you can filter a list of object elements using the OfType function to only keep those that can be converted to the string type:  object[] objects = ...
var strings = objects.OfType();  Only the components that can be cast to the string type are maintained in the new sequence when the OfType function is used on the objects array in this example.   In conclusion, the Cast method of LINQ can be used to change the type of elements in a sequence by casting them to a specific type; it accepts a sequence of one type and returns a new sequence of a different type, where each element is cast to the provided type. To avoid this, use the OfType method, which filters the sequence and only keeps the items that can be cast to the specified type. If the elements cannot be cast to the specified type, the Cast function will throw an exception.