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

The Archive Base Latest Questions

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

I have a function that has a signature of Update(IEnumberable<INotifyPropertyChanging> things) and a class

  • 0

I have a function that has a signature of

Update(IEnumberable<INotifyPropertyChanging> things)

and a class

doohickey : INotifyPropertyChanging, INotifyPropertyChanging{}

When I try to do

List<doohickey> doohickeys = new List<doohickey>();
Update(doohickeys);

An exception gets thrown stating:

cannot convert from 'System.Collections.Generic.List<doohickey>' to 'System.Collections.Generic.IEnumerable<System.ComponentModel.INotifyPropertyChanging>'

What gives? Doohickey inherits the INotifyPropertyChanging interface and List inherits the IEnumerable interface! How come simply passing the object and expecting it to get cast down doesn’t?

I’ve included the references to INotifyPropertyChanging to signify that doohickey is actually a linq-to-sql class; in case that bit of context matters.

  • 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-18T20:16:21+00:00Added an answer on May 18, 2026 at 8:16 pm

    This won’t work because there is no implicit conversion between List<doohickey> and IEnumerable<NotifyPropertyChanging>. You need to call:

    Update(doohickeys.Cast<INotifyPropertyChanging>());
    

    The reason behind this is type safety. In C#4, co-/contravariance was added to the language, which generally helps making these type of conversions valid. There are some limitations though, since the type involved needs to be declared co-/contravariant, and it only applies to interfaces and delegates.

    The reason why you can’t implicitly convert List<T> to List<TBase> is, that it would make this code valid:

    List<T> values = new List<T>();
    // add some values...
    List<TBase> bases = values;
    bases.Add(new TBase());  // Woops. We broke type safety by adding a TBase to a list of T's
    

    Now, if you tried to do this when values was of type IEnumerable<T>, it would be valid in C#4. This is because you can only get values out of IEnumerable<T>, so we don’t need to worry about lesser types being added. Therefore IEnumerable<T> is covariant, and is declared as:

    IEnumerable<out T>
    

    Where out means “covariant”. (The keywords is actually the best way to remember which way values may go in a variant type.

    Co-/contravariance is a rather large subject, but this article does a good job of explaining the most important parts. And if you want to learn more, Eric Lippert has an 11-part blog post series about the feature. Eric is one of the language designers.

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

Sidebar

Related Questions

I have a function that has a signature of Update(IEnumberable<INotifyPropertyChanging> things) and a class
I have a member function in a class that has a callback, but the
I have been trying to call a C function that has the following signature
A template function I have written has the following signature: template<class IteratorT> auto average(IteratorT&
I have a function that has the signature of: function(id,target){ //do stuff } The
Now I have a function that has to return a string. I saw a
I have a function that generates a key of 4 characters that has to
gcc 4.4.2 c89 I have a function that has to run (config_relays). It make
I have a control that has a Filter property that expects a function that
I have a bash script that has this function in it: function start_vi() {

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.