How to create extension method on generic collection

You were close, just need the <T> after the method name before the parenthesis. That’s where the generic type parameter list for generic methods is placed. It declares the generic type parameters the method will accept, which then makes them available to be used in the arguments, return values, and method body.

public static class Extensions
{
    public static void MoveToTop<T>(this ICollection<T> sequence)
    {
        //logic for moving the item goes here.
    }
}

Leave a Comment

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