简体   繁体   中英

analog of java wildcard (generic type) in c #

I rewrite the code with java on .net c # confronted with the problem of transfer classes with wildcard. There are two classes

public abstract class Client <T extends Connection <? >>
public class Connection <T extends Client <? >>

I thought we could have done so

public abstract class Client <T> where Connection <U>

but it turned out that even here does not work

public abstract class Client <T, U> where Connection <T, U>
public abstract class Connection <T, U> where Client <T, U>

so how to get out of the situation?

You can do the following:

public class Connection<T>
{
}

public abstract class Client<T, U> where T : Connection<U>
{
}

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