Partial Generics in C#

Kathiresan Moorthy 21 Reputation points
2022-01-24T17:13:54.4+00:00

Hello Team,

This may sound dumb, but not sure if we've any ability to implement Partial Generics in C#. Like, instead of defining a class to be generic, I would like to define a class partial generic. I dont find a way doing this. Am I missing something obvious here or do I have not enough understanding on how Generics are defined.

I was trying to implement class something like this.

public class MyUtilClass<T<MyWellKnownBase>>
{

}

or something like

public class MyUtilClass<MyWellKnownBase<T>>
{

}

This would give me a flexibility to define partial implementation in my util class rather than fully making the class generic of type T.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,391 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Kathiresan Moorthy 21 Reputation points
    2022-01-24T18:26:56.51+00:00

    Hello vb2ae,

    Appreciate your time and suggestion. I guess that should work. I tried something like below and seems to be what am looking for!

    public class Gen1<T>
    {

        }
    
        public class Gen2<T, K> where T: Gen1<K>
        {
    
        }
    
    0 comments No comments