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?
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://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-type-parameters
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.