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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:44:44+00:00 2026-05-13T20:44:44+00:00

From the book: 1) int i = 7; 2) Object o = i; //

  • 0

From the book:

1) int  i  =  7;
2) Object  o  =  i; //  Implicit  boxing  int-->Object
3) Object[]  a3  =  new  int[]  {  1,  2  }; //  Illegal:  no  array  conversion

The assignments in 3) is illegal
because int is not a reference type
and so int[] is not implicitly
convertible to Object[]

I don’t get this . on line 2) it shows that int is implicitly convertible to Object, and in the third line, it says int[] is not implicitly convertable. wha ??

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

    Not to restate the problem, but it’s because int[] is not implicitly (or explicitly, for that matter) convertible to Object[].

    Arrays are types in and of themselves. int[] simply means “a series of int variables”, just like Object[] means “a series of Object variables”.

    Incidentally, all arrays are reference types, it’s just that int[] is a reference type representing a series of a particular value type.

    EDIT

    Don’t allow the talk about covariance to confuse you. This is a widely misunderstood topic, and one that’s not really beneficial for a beginning developer to try to tackle. Yes, .NET 4.0 introduces the ability to specify an operation as being covariant or contravariant, but that won’t allow for assignment compatibility between incompatible types like Object[] and int[]. Consider the following example, assuming that it would compile.

    int[] ints = new int[] { 1, 2, 3 };
    Object[] objects = ints;
    
    objects[1] = "hello";
    int foo = ints[1];
    

    Now we have a problem. If it were legal to assign an int[] to an Object[], then I now suddenly (magically) have a string value in my int[] array–something that should never happen, and actually can’t happen, since an int variable cannot hold a string value.

    Others have (correctly) pointed out that something like this does compile:

    string[] strings = new string[] { "a", "b", "c" };
    Object[] objects = strings;
    
    objects[1] = 4;
    

    I’ll leave it to someone like Eric Lippert to explain why this sort of operation works (it’s essentially assuming covariance when it isn’t necessarily the case) [EDIT: Thanks to Tim Goodman, who actually posts Eric’s explanation, or at least statement, about this], but fundamentally any reference type is technically capable of holding a reference to any type. In other words, when I declare a string variable it allocates the same amount of memory (for the variable) as if I were to declare a DbConnection variable; they’re both reference types. For value types, the amount of memory allocated depends on the type, and they are fundamentally incompatible.

    You will note, however, that you will get a runtime exception (ArrayTypeMismatchException) when performing the last step (assigning an int to the second array element), since the underlying array is actually a string[].

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

Sidebar

Ask A Question

Stats

  • Questions 395k
  • Answers 395k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Depending on the type you want: public double time; or… May 15, 2026 at 2:45 am
  • Editorial Team
    Editorial Team added an answer Set a global determined by the behavior of IE's conditional… May 15, 2026 at 2:45 am
  • Editorial Team
    Editorial Team added an answer If you are needing an ordered list why not use… May 15, 2026 at 2:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.