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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:54:21+00:00 2026-05-31T10:54:21+00:00

This is a followup on a thread I thought was resolved yesterday. Yesterday I

  • 0

This is a followup on a thread I thought was resolved yesterday. Yesterday I was having problems with my code in the following case:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        class Bar
        {
            int v;

            public Bar(int v) { this.v = v; }
            public override string ToString() { return v.ToString(); }
        }

        static void Main(string[] args)
        {
            Foo(1, 2, 3);
            Foo(new int[] { 1, 2, 3 });
            Foo(new Bar(1), new Bar(2), new Bar(3));
            Foo(new Bar[] { new Bar(1), new Bar(2), new Bar(3) });
            System.Threading.Thread.Sleep(20000);
        }

        static void Foo(params object[] objs)
        {
            Console.WriteLine("New call to Foo: ");
            foreach(object o in objs)
                Console.WriteLine("Type = " + o.GetType() + ", value = "+o.ToString());
        }
    }
}

If you run this you can see a problem with the last call to Foo. The fact that the argument is a vector is “lost”.

So…. anyone know how to report a C# compiler bug? Or would this be considered a reflection bug?

(What a relief: I was bummed to think I had wasted time here with a bug of my own. In fact it is a C# bug after all, and I’m vindicated! And how often do we get to see actual C# compiler bugs these days? Not common…)

  • 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-31T10:54:23+00:00Added an answer on May 31, 2026 at 10:54 am

    I would expect these two calls to function identically- a params argument is an array in the called method. Jon Skeet’s example in the previous question works because an array of int’s is not covariant to an array of objects (and so is treated as new Object[] { new Int[] {1,2,3} }), but in this example an array of FooBars is covariant to an array of objects, and so your parameter is expanded into the objs argument.

    Wikipedia of all things covers this exact case: Covariance and contravariance (computer science)

    Sorry but I am sure that this is not a compiler bug.

    EDIT:

    You can achieve what you want thus:

    Foo(new Object[] { new Bar[] { new Bar(1), new Bar(2), new Bar(3) } });
    

    NEW EDIT (other author):

    Or simply use:

    Foo((Object)new Bar[] { new Bar(1), new Bar(2), new Bar(3) });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a followup to a question I posted yesterday. I thought everything was
I post this question has followup of This question , since the thread is
Background: This is a follow-up question to this thread about handling EINTR for system
The question is basically a follow up to this thread: Using a 64 bit
This is a followup on my previous question , I am using the 2to3
This is kind of a followup to this question . I have the following
This is a followup to this question. Here's the code I'm trying to understand
This is kind of a followup to the question I had yesterday. I had
This is a followup to the solution for this question. I am using jQuery's
This is a followup to an earlier question ( Help Refining RegEx ("\b\d{6}([ ]{1,15})\d{7}\b")

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.