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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:16:51+00:00 2026-05-11T07:16:51+00:00

Recently I found a very surprising behavior in c#. I had a method which

  • 0

Recently I found a very surprising behavior in c#. I had a method which takes IEnumerable<Object> as a parameter and i was passing IEnumerable<string> but it’s not possible. While in c# everything can be upcast to Object than why this is not possible? It’s totally confusing for me. Please someone clear me on this issue.

  • 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. 2026-05-11T07:16:51+00:00Added an answer on May 11, 2026 at 7:16 am

    The technical term for this is that generics are invariant in C# 3.0 and earlier. From C#4.0 onward, the cast works.

    What invariant means is that there is no relationship between two generic types just because their generic type parameters are related (i.e. are sub- or supertypes of each other).

    In your example, there is no typing relationship between an IEnumerable<object> and an IEnumerable<string>, just because string is a subtype of object. They’re just considered two completely unrelated types, like a string and an int (they still both are subtypes of object, but everything is)

    There are a few workarounds and exceptions for this issue you’ve run into.

    First, you can cast each string individually to object, if you’re using .NET 3.0 you can do that using the Cast<T>() extension method. Otherwise, you can use a foreach and put the result into a new variable of the static type you want.

    Second, arrays are an exception for reference type, i.e. passing in a string[] type to a method acccepting object[] types should work.

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

Sidebar

Related Questions

I am very new to Rails, I am running Rails 3 I recently installed
I first started C++ with Microsoft VC++ in VS2010. I recently found some work,
I recently was browsing a local web design firm's portfolio and found all their
I recently came across the subject of exact real arithmetic after reading this paper
I run into what seems to be a very classical problem: An item and
I'm looking for PHP5 ORM which fully supports composite (multi-column) relations based on composite
I want to describe an issue I have been having with Plot using With
This is probably really simple, I know you can change css properties with javascript
I've been working intermittently on an Excel spreadsheet for a customer that does some
I have an existing Paperclip setup that converts all uploaded images to JPG's. However,

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.