© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
23 replies
Starlk

❔ a question about generics

vague title because I don't know how would I word it

void Welcome<T>(T message) where T : Parent<T> { }

internal abstract record Parent<T>();

internal sealed record Child() : Parent<string>;
void Welcome<T>(T message) where T : Parent<T> { }

internal abstract record Parent<T>();

internal sealed record Child() : Parent<string>;


this might be a weird question, but how could I achieve something like this:
Welcome<Child>("string");
Welcome<Child>("string");

where the provided T type might change the
message
message
type, for example, if
Child
Child
was
Parent<int>
Parent<int>
then Welcome<Child>() would for an integer
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Generics question
C#CC# / help
2y ago
Generics, Constraints and a simple question
C#CC# / help
12mo ago
❔ A question about buttons, interfaces
C#CC# / help
4y ago
❔ Generics
C#CC# / help
3y ago