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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:22:24+00:00 2026-05-13T00:22:24+00:00

I just noticed a strange behavior with overload resolution. Assume that I have the

  • 0

I just noticed a strange behavior with overload resolution.

Assume that I have the following method :

public static void DoSomething<T>(IEnumerable<T> items)
{
    // Whatever

    // For debugging
    Console.WriteLine("DoSomething<T>(IEnumerable<T> items)");
}

Now, I know that this method will often be called with a small number of explicit arguments, so for convenience I add this overload :

public static void DoSomething<T>(params T[] items)
{
    // Whatever

    // For debugging
    Console.WriteLine("DoSomething<T>(params T[] items)");
}

Now I try to call these methods :

var items = new List<string> { "foo", "bar" };
DoSomething(items);
DoSomething("foo", "bar");

But in both cases, the overload with params is called. I would have expected the IEnumerable<T> overload to be called in the case of a List<T>, because it seems a better match (at least to me).

Is this behavior normal ? Could anyone explain it ? I couldn’t find any clear information about that in MSDN docs… What are the overload resolution rules involved here ?

  • 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-13T00:22:25+00:00Added an answer on May 13, 2026 at 12:22 am

    Section 7.4.3 of the C# 3.0 specification is the relevant bit here. Basically the parameter array is expanded, so you’re comparing:

    public static void DoSomething<T>(T item)
    

    and

    public static void DoSomething<T>(IEnumerable<T> item)
    

    The T for the first match is inferred to be List<string> and the T for the second match is inferred to be string.

    Now consider the conversions involved for argument to parameter type – in the first one it’s List<string> to List<string>; in the second it’s List<string> to IEnumerable<string>. The first conversion is a better than the second by the rules in 7.4.3.4.

    The counterintuitive bit is the type inference. If you take that out of the equation, it will work as you expect it to:

    var items = new List<string> { "foo", "bar" };
    DoSomething<string>(items);
    DoSomething<string>("foo", "bar");
    

    At that point, there’s only one applicable function member in each call.

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

Sidebar

Related Questions

I just noticed a strange behavior which looks like a bug. Consider the following
Just today I noticed a strange behavior in an object model that was previously
I have just noticed a strange behavior of ComboBox component. I am using it
I just noticed while creating a RESTful WCF service that the Method parameter on
I just noticed that java.beans.Introspector getBeanInfo does not pickup any superinterface's properties. Example: public
i have just noticed something strange in some asp.net markup. I have a standard
I have a couple of UITableViewController classes and I just noticed that these methods
I am creating a responsive website, and have just noticed a strange behaviour in
I have noticed that with Delphi 2009, I often get strange errors when compiling,
I am getting some strange behavior involving database queries that I have never seen

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.