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 8684207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:14:55+00:00 2026-06-12T22:14:55+00:00

I have often wanted to create a list of objects where each object must

  • 0

I have often wanted to create a list of objects where each object must implement a number of interfaces. For example, I’d like to do something similar to the following:

List<T> where T : IConvertible, IComparable _myList;

Another option I considered was to create a third interface that implements these two so that any object that implements these two interfaces inherently implements mine.

public interface IConvertibleAndComparable
    : IConvertible, IComparable { }

List<IConvertibleAndComparable> _myList;

With this I would be able to add any object that implements both IConvertible and IComparable, including double and int, as well as my own objects. Explicitly implementing IConvertibleAndComparable is not required since it does not add any new functionality beyond the interfaces in inherits.

I understand that the first snippet is illegal and the second, while legal, does not do what I want. Is it possible to achieve what I am trying to do? If not, would either of these be a candidate for a future C# feature?

(Note: This would be legitimate application for empty interfaces.)

Edit

In a more general sense, I’d like to perform one of the following:

private MyGenericClass<T> where T : IA, IB, ... _myClass;

where I can declare all of the restrictions on T that I need, or

public interface IMyCombinedInterface : IA, IB, ... {}
private MyGenericClass<IMyCombinedInterface> _myClass;

where any type that implements IA, IB, and ... inherently (or implicitly) implements IMyCombinedInterface (only when IMyCombinedInterface doesn’t explicitly declare new functionality).

  • 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-06-12T22:14:56+00:00Added an answer on June 12, 2026 at 10:14 pm

    You can, as a workaround, do a kind of superposition wrapper, and store it in the list. Look here for the idea.

    To your example you could do:

    public class Junction
    {
        public IConvertible Convertible { get; private set; }
        public IComparable Comparable { get; private set; }
        private Junction() { }
        public static Junction Create<T>(T value) where T : IConvertible, IComparable
        {
            return new Junction
            {
                Convertible = value,
                Comparable = value
            };
        }
    }
    

    And then add Junctions to your list:

    var l = new List<Junction>();
    l.Add(Junction.Create(1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have often seen the spinning gears OpenGL example ( I think originally done
I quite often have rows of code like the following: UPDATE my_table SET name
I have found that I often have to implement some sort of a scheduler
Several times I've wanted to traverse a list and pick out elements that have
This is something I've often wanted to be able to do while debugging. If
i often have in java projects a lot of small helper(storage) classes like 2-Tuple,
So often you will have a number of labels (lets use name, age, colour)
In trying to learn how to create objects in ActionScript, I have had no
I have often encountered an error such as cannot convert from 'method group' to
I have often PATHs for files which do not exist in my codes. I

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.