I am trying to generalize my “Last” extension method to be used with a list of any data type:
public static CartesianPoint Last(this List<CartesianPoint> MyList)
{
return MyList.ElementAt(MyList.Count - 1);
}
“CartesionPoint” is a custom struct. I would like this function to work with a list of any data type. Is this possible? Is using an ‘object’ the only way?
Last is a supported Linq expression, but if you do want to write a generic extension method, this is the syntax you’re looking for: Put the generic
<T>on the method declaration, not on the class.