© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
96 replies
Loup&Snoop

✅ Class as a field?

Suppose I have Class1, Class2, and Class3. Class2 is just a container of information. At runtime I want Class1 to look into the contents of Class2, find Class3, and instantiate an instance of Class3.

For this, I DO NOT WANT class2 to have an instance of class3, and I do not want class2 to have any code/knowledge of what class3 is going to do. In theory, I want Class2 to have a field which gives a type that implements a specified interface that allows Class1 to call it.

Is there a way to do this?
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
Next page

Similar Threads

❔ can a static class contain static class as property
C#CC# / help
3y ago
Splitting a large class and problems with a field needed in multiple classes as a result
C#CC# / help
3y ago
❔ Class with parameter as a generic parameter
C#CC# / help
4y ago