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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:02:03+00:00 2026-05-25T12:02:03+00:00

I previously asked this as ‘double covariance’ and realized that I had things upside

  • 0

I previously asked this as ‘double covariance’ and realized that I had things upside down

I have an interface

public interface INodeProvider
{
    void LoadNodes(INode parent, Action<IEnumerable<INode>> action);
}

I have a class derived from INode, called DeviceNode

I have a class that implements the interface

public override void LoadNodes(INode parent, Action<IEnumerable<INode>> action)
{
                List<DeviceNode> devices = new List<DeviceNode>();
                foreach (var dev in list)
                {
                    devices.Add(new DeviceNode(this, dev));
                }
                action(devices);
}

This does not compile. But this does

                List<INode> devices = new List<INode>();

It also compiles if I do

 action(devices.Cast<INode>());

And revert back to my original declaration

This surprised me. Maybe I need to read more.

But I have another question. The delegate being invoked (action), really needs to know the type of the object in the IEnumerable. ie I want to do

Type[] typeParameters = l.GetType().GetGenericArguments();

in the action method. I assume this will give me the actual type used to instantiate the IEnumerable. Except its always INode given what I can get to compile. I was surprised that the one with Cast<>() on it still said INode given that the underlying type is List{DeviceNode} (I guess this means that .Cast actually copies)

Note – I know I could inspect the objects in the collection to determine their type, but that’s not what I want to do

EDIT: This seems to be a difference between Silverlight 4 and ‘normal’ .net 4. If I take the same code and paste it into a .net 4 project it compiles fine

  • 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-25T12:02:04+00:00Added an answer on May 25, 2026 at 12:02 pm

    This is a feature missing from SL4 (Ienumerable is not marked ‘out’). Apparently fixed in SL5

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

Sidebar

Related Questions

When I asked this previously I should have mentioned that it's particularly a light-weight
From this previously asked question , I have noticed that when I move a
OK, I know that this has been asked previously, so please forgive me for
Possible Duplicate: what is this weird code notation mean I have previously asked this
I asked this question previously and thought I had it figured out but it
I have a problem similar to this question which was previously asked but my
I have tried setting this up based on previously asked questionshere on stack overflow
I have seen this question asked previously but can not find a clear explanation
Ok, I have previously asked a similar question to this but it was voted
I didn't see any questions that asked this previously so here goes: Once you

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.