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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:27:47+00:00 2026-06-11T16:27:47+00:00

Why the property get the error while the method can be compiled? public interface

  • 0

Why the property get the error while the method can be compiled?

public interface IFoo {}
public interface IBar<out T> where T : IFoo {}

public interface IItem<out T> where T: IFoo
{
    // IEnumerable<IBar<T>> GetList(); // works
    IEnumerable<IBar<T>> ItemList { get; set; } // Error!
}

Error:

Invalid variance: The type parameter ‘T’ must be contravariantly valid
on ‘UserQuery.IItem<T>.ItemList’. ‘T’ is covariant.

  • 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-11T16:27:48+00:00Added an answer on June 11, 2026 at 4:27 pm

    You get the compiler error because you have a property getter (get) and a setter (set). The property getter has the T in it’s output so out works, but the property setter will have the T in its input so it would need the in modifier.

    Because you have out on T you need to remove the setter and it will compile:

    public interface IItem<out T> where T : IFoo
    {
        // IEnumerable<IBar<T>> GetList(); // works
        IEnumerable<IBar<T>> ItemList { get; } // also works
    }
    

    If your T is an in generic argument then the following would work:

    public interface IItem<in T> where T : IFoo
    {
        IEnumerable<IBar<T>> ItemList { set; } 
    }
    

    But you cannot have both (out,in) at the same time so you cannot have a co/contravariant property with a getter and a setter.

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

Sidebar

Related Questions

I get the following error: 1119: Access of possibly undefined property color through a
I am having a hard time figuring out how to get the property list
I have an attribute declared on property. How can I get the property name
While running my code I get the error TypeError: Error #1009: Cannot access a
I can't realize why do I have 404 error while trying to access /liginform.dlp
No matter how I configure the Credentials property I get a 401 exception when
I'm trying to use the jQuery .attr() property to get the height of an
Permission denied for <http://example.com> to get property HTMLDocument.body from http://www.example.com . var c =
What I am trying to do is, get the property value of the selected
I get this: BadValueError: Property is 804 bytes long; it must be 500 or

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.