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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:39:37+00:00 2026-05-17T06:39:37+00:00

I recently started to think of this problem and I can’t find the answer.

  • 0

I recently started to think of this problem and I can’t find the answer.
The following code compiles and executes as expected

object[] test = new string[12];

However, I don’t know why.

I mean, should we consider string[] as the derived class of object[]?
I think in C#, every array is an instance of Array class. If Array is generic, it should be Array<T>, and Array<string> can be assigned to Array<object>, it doesn’t make sense. I remember only interface can use in/out keyword.

And in Java, I’m not sure, but still feel weird. Why different types of references can be possibly assigned to each other when they don’t have super-sub class relationship?

Can somebody explain a little?

Thanks a lot!

  • 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-17T06:39:37+00:00Added an answer on May 17, 2026 at 6:39 am

    It’s because reference type arrays support covariance in both Java and C#. It also means that every write into a reference type array has to be checked at execution time, to make sure you don’t write the wrong type of element into it 🙁

    Don’t forget that both Java and C# (and .NET in general) started off without generics. If they had had generics to start with, life could have been somewhat different.

    Note that both Java and C# support generic variance now, but in rather different ways. So for example in C# 4 you can write:

    IEnumerable<string> strings = // Get some string sequence here
    IEnumerable<object> objects = strings;
    

    but you can’t write

    IList<string> strings = // Get some string list here
    // Compile-time error: IList<T> isn't covariant in T
    IList<object> objects = strings;
    

    This wouldn’t be safe, because you can add to an IList<T> as well as taking items from it.

    This is a big topic – for more details, see Eric Lippert’s blog series.

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

Sidebar

Related Questions

This problem has only cropped up recently, but I couldn't find any reference to
I recently started working with a client that had an index.html file with this
I am not an expert on VBA as I've recently started looking into this.
I recently started following the online course on iPhone development from Stanford University on
I have recently started learning F#, and this is the first time I've ever
I recently started to use the Nodewords module in Drupal 6. This adds the
A problem has started occurring recently in which some new files added to the
I recently started using Masterpages, the thing is I would like to add text
I just recently started to experiment with .NET MVC 4. The thing is I
I started a demonstration project on HTML, JSON and jQuery recently. Thing I want

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.