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

  • Home
  • SEARCH
  • 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 501593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:12:20+00:00 2026-05-13T06:12:20+00:00

So I have an object, lets say Item<U> . I want to create a(n)

  • 0

So I have an object, lets say Item<U>. I want to create a(n) (I)List<T> containing a collection of these items. The problem that I am running into is that the collection of Item<U> can have any number of different types for U in them.

What I can not figure out is the signature to use for the IList. I tryed IList<Item<T>>, but because I do not (in the class where the IList is to be used) have a defination of T (which as I said varys anyhow) I can not use this signature. What is the best way to approach this requirement?

  • 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-13T06:12:20+00:00Added an answer on May 13, 2026 at 6:12 am

    You need to add a non-generic interface to your Item<U> and make the collection out of those interfaces.

    There is no way you can create a collection of IList<Item<T>> where T is some base type for a lot of different object types you want to place into the same list. This is co(ntra)-variance in place which specifically prohibits this.

    So you need to instead add something common, that isn’t generic, and make the list out of that. For instance, you might make Item<T> implement IItem, and create IList<IItem> instead.

    That’s the best you can do.

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

Sidebar

Related Questions

Lets say I have query that gets following List Item Objects with Set of
Lets say I have an object that has stringProp1, stringProp2. I wish to store
For example lets say I have a JSON object that contains states and cities.
Lets say that I have a JSON object called fruits and this is the
Lets say I have a single object of type Car which I want to
Lets say that you have a business object whose current state implies that there
Lets say I have a List<object> which is passed into a class as an
Lets say I have an object with two boolean properties: public bool AdvancedMode{ get;
I have an object in C# with lets say 20 properties and it's part
I have a question regarding events in c#. Lets say I have an object

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.