简体   繁体   中英

How to create Generic class that takes unlimited type

I want to create a Generic class that can take unlimited types. I mean;

If i want to create a generic class that takes 2 different types i have to write it like below;

public class ClassName<T1, T2> { }

But if i want to create a generic class that takes 3 different types i have to write it like below;

public class ClassName<T1, T2, T3> { }

But i want to create a class that can take 2 or 3 or more different types without creating new classes. With just one class definition.

Is it possible?

C# does not support variadic generics, so no, what you're describing is not possible. What specific problem are you trying to solve?

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