简体   繁体   中英

What does it mean when angle brackets are used after an interface?

My sample code has the following:

public class IdentityUser : IdentityUser<string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>, 
    IUser, 
    IUser<string>
{

I understand that the IdentityUser must implement the IUser methods but can someone explain what it means:

IdentityUser<string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>

The angle brackets are notation for generics. I recommend reading documentation on C# generics, such as http://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx .

Wherever IdentityUser is defined is something similar to this:

public interface IdentityUser<A,B,C,D> {
  // ...
}

So if you make the following class:

public class MyClass : IdentityUser<string, string, string, string> {
  // ...
}

Then it is saying that MyClass implements IdentityUser and that the type variable A is string , the type variable B is string , and so on.

That is not easy to explain, but it means that the type is a generic one. You should read the relevant topic in the MSDN library for details or maybe the Wikipedia article for an overview of the concept in general.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM