Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1030471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:42:20+00:00 2026-05-16T12:42:20+00:00

Is there anyway to force a constraints for a generic definition to implement a

  • 0

Is there anyway to force a constraints for a generic definition to implement a “generic interface” … that is, I want the class to support passing an interface and a generic class constraining it so that the class implements the interface. For example if I say:

MyGenericClass<IMyInterface, MyImplementation>.DoSomething();

That should be constrained so that MyImplementation implements IMyInterface

As far as I know that can be achieved by

public class Dynamic_Loader<T, S> where S: T

Now, is there anyway to also force T to be an interface?

Edit: The purpose of this was to have something like:

private static List<T> interfaceList = new List<T>();

public static List<T> InterfaceList {get { return interfaceList;}}

public static void Add(S input) { interfaceList.Add(input);}

and have the list restricted to only interfaces (since it is supposed to return implementations of certain interfaces)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:42:21+00:00Added an answer on May 16, 2026 at 12:42 pm

    Do you mean, can a constraint also be put on T like where T : interface?

    If so, then no: this list pretty much covers your options.

    What you have is as close as it gets, I believe.

    Out of curiosity, what would be your reason for wanting to constrain T to be an interface?

    Or do you mean can a constraint also be put on T for T to implement some specific interface?

    If so, then yes: simply have two where clauses (e.g., where S : T where T : U).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway to force Internet Explorer to prompt for download of XML files
I'd like to know if there's any way to force the System.Net.Dns class to
Is there anyway or any addin for VS2010 that can remove all the comments
Is there anyway to force XAML to completely redraw all of its elements and
Is there anyway I can do this? class TSOC<TCollection, TValue> : ICollection<TValue>, INotifyCollectionChanged where
I'm wondering is there anyway I can force popup.html to close?
Is there anyway to force angular to update/recompile the variables within a binding? I'm
Using Delphi 7, is there anyway to force inputbox to allow only numbers entry
Is there anyway to force a TSpeedButton to be redrawn flat? When using a
Is there anyway to force a mouse click using C++ outside of my application?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.