Kshitij Rodrigues
Kshitij Rodrigues

Reputation: 35

What is meant by Class<Type> in C#?

What is meant by Class in C# ? eg public interface IUser

public class CustomUser : IUser<string>
{
    public string Id { get; set; }
    public string UserName { get; set; }
}

In above case what we call IUser class and why we have in front of it?

Upvotes: 0

Views: 92

Answers (2)

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

Imagine that IUser interface looks like this;

public interface IUser<T>
{
    void A(T a);
}

And the CustomUser class should be like this;

public class CustomUser : IUser<string>
{
    public string Id { get; set; }
    public string UserName { get; set; }

    public void A(string a)
    {

    }
}
var customUser = new CustomUser();
customUser.A("Sample");

You tell it that A method parameter must be string for CustomUser : IUser<string>

Upvotes: 0

whites11
whites11

Reputation: 13260

IUser is a so called generic interface. It's an interface that changes its definition (return types and parameters of the functions) based on the type put between the angular brackets.

More here: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-type-parameters

Upvotes: 1

Related Questions