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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:59:48+00:00 2026-06-15T05:59:48+00:00

Why does var value = new Guid[]{}; var b = (object[])value; results in Cannot

  • 0

Why does

var value = new Guid[]{};
var b = (object[])value;

results in

Cannot cast 'value' (which has an actual type of 'System.Guid[]') to 'object[]'

?

UPDATE

Sorry for inaccuracy. The real code is:

    private void SetEditors(object value)
    {
        var array = value as object[];
        ...
    }

and array is null if value is Guid array.

  • 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-06-15T05:59:50+00:00Added an answer on June 15, 2026 at 5:59 am

    To answer the "why" part- only arrays of reference types are covariant.

    So you can write:

    string[] x = new string[10];
    object[] y = x;
    

    But you can’t write:

    int[] x = new int[10];
    object[] y = x;
    

    Personally I think it’s a shame that even the first version is allowed, but that’s a different story.

    This is all detailed in section 6.1.6 of the C# 4 spec (Implicit Reference Conversions):

    The implicit reference conversions are:

    • …
    • From an array-type S with an element type SE to an array-type T with an element type TE provided all of the following are true:
      • S and T differ only in element type. In other words, S and T have the same number of dimensions.
      • Both SE and TE are reference-types.
      • An implicit reference conversion exists from SE to TE
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

javascript with> var customer=document.getElementById('custList').value; and that works... Why does it work BUT... var customer=(form1.custList.value);
var object = {foo: 'bar'}; Does JavaScript have a way to determine that object.foo
Why does this code always return 0? var possibleMatches = new Array(); $.getJSON('getInformation.php', function(data)
I have a javascript file which has some code somewhat like this: var Slide
I have just cast a 08/23/2012 to date in javascript: var value = '08/23/2012';
I've got a table which has a button to add a new row. When
The following code does not submit the input values: $('.button').live('click', function() { var date
Does anyone know how to write this var q = from c in customers
Does anyone know of a Java library that provides support for the ${var} style
why does this only alert 1 ? function test() { var myobj = {

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.