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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:31:11+00:00 2026-05-28T08:31:11+00:00

A couple of month ago I wrote a simple program in Java. I have

  • 0

A couple of month ago I wrote a simple program in Java.

I have two overloaded methods called F and one of them takes variable length argument.
This program will not compile, because calling F(4) in main method is ambiguous and the
compiler does not know which method to choose.

class Example
{
    static void F(int... array)
    {
        Console.WriteLine("We are in first method");    
    }

    static void F(int x, int ... array)
    {
        Console.WriteLine("We are in second method");    
    }

    static void main()
    {
        F(4);
    }
}

I wrote an equivalent program in C# as below and I was expecting a compile-error.
Surprisingly the program compiled successfully without any error.

The output of the program is “We are in second method” which means that the second
overloaded method was chosen !!!

Isn’t this strange ?? Both F methods can be a candidate for calling, but why CLR chooses the second overloaded method ???

class Example
{
    static void F(params int[] array)
    {
        Console.WriteLine("We are in first method");    
    }

    static void F(int x, params int[] array)
    {
        Console.WriteLine("We are in second method");    
    }

    static void Main()
    {
        F(4);
    }
}
  • 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-28T08:31:12+00:00Added an answer on May 28, 2026 at 8:31 am

    C# takes that approach because it says so in the C# language specification:

    7.4.3.2 Better function member Given an argument list A with a set of argument expressions { E1, E2, …, EN } and two applicable function
    members MP and MQ with parameter types { P1, P2, …, PN } and { Q1,
    Q2, …, QN }, MP is defined to be a better function member than MQ if

    • for each argument, the implicit conversion from EX to QX is not
    better than the implicit conversion from EX to PX, and

    • for at least one argument, the conversion from EX to PX is better than the
    conversion from EX to QX. When performing this evaluation, if MP or MQ
    is applicable in its expanded form, then PX or QX refers to a
    parameter in the expanded form of the parameter list. In case the
    parameter type sequences {P1, P2, …, PN} and {Q1, Q2, …, QN} are
    identical, the following tie-breaking rules are applied, in order, to
    determine the better function member.

    • If MP is a non-generic method and MQ is a generic method, then MP is better than MQ.

    • Otherwise, if MP is applicable in its normal form and MQ has a params array and is
    applicable only in its expanded form, then MP is better than MQ.

    • Otherwise, if MP has fewer declared parameters than MQ, then MP is
    better than MQ. This can occur if both methods have params arrays and
    are applicable only in their expanded forms.

    • Otherwise, if MP has
    more specific parameter types than MQ, then MP is better than MQ. Let
    {R1, R2, …, RN} and {S1, S2, …, SN} represent the uninstantiated and
    unexpanded parameter types of MP and MQ. MP’s parameter types are more
    specific than MQ’s if, for each parameter, RX is not less specific
    than SX, and, for at least one parameter, RX is more specific than SX:

    o A type parameter is less specific than a non-type parameter.

    o Recursively, a constructed type is more specific than another
    constructed type (with the same number of type arguments) if at least
    one type argument is more specific and no type argument is less
    specific than the corresponding type argument in the other.

    o An array type is more specific than another array type (with the same number of
    dimensions) if the element type of the first is more specific than the
    element type of the second.

    • Otherwise if one member is a non-lifted
    operator and the other is a lifted operator, the non-lifted one is
    better.

    • Otherwise, neither function member is better.

    EDIT: Had the wrong section highlighted. Fixed now.

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

Sidebar

Related Questions

I read an article about a month ago about a couple of methods you
I have a huge disgusting stored procedure that wasn't slow a couple months ago,
A couple of weeks ago i have started my research in Iphone app development
I have completed my website couple months ago, in php 5 (full oop), and
We have to automate database updation couple of times a month. My current use
I have implemented a couple of months ago the in app auto renewable subscription
Couple of months ago, we revamped our web site. We adopted totally new site
A couple of months ago I've coded a tiny tool that we needed at
A couple of months ago I was doing Javascript programming on the Facebook platform,
I've dived into the GWT world a couple of months ago and find it

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.