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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:04:55+00:00 2026-05-31T23:04:55+00:00

Given the following method signature, why is it when a parameter is explicitly named

  • 0

Given the following method signature, why is it when a parameter is explicitly named the compiler is unable to automatically infer the type? Visual Studio 2010 SP1 is able to infer the type and shows no warnings or errors.

IEnumerable<T> ExecuteCommand<T>(
    string commandText,
    string connectionName = null,
    Func<IDataRecord, T> converter = null) { ... }

static SomeClass Create(IDataRecord record) { return new SomeClass(); }

void CannotInferType() {
    var a = ExecuteCommand(
        "SELECT blah",
        "connection",
        converter: Test.Create);
}

void CanInferType() {
    var a = ExecuteCommand(
        "SELECT blah",
        "connection",
        Test.Create);
}

Calling it as described in CannotInferType and when attempting to compile it the compiler emits error CS0411: The type arguments for method 'Test.ExecuteCommand<T>(string, string, System.Func<System.Data.IDataRecord,T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Whereas calling it as described in CanInferType works as expected.

As stated above, Visual Studio itself reports no problems, and intellisense for the variable a shows IEnumerable<SomeClass> as expected but for some reason it doesn’t compile.

  • 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-31T23:04:57+00:00Added an answer on May 31, 2026 at 11:04 pm

    It was a bug in the C# 4 compiler. It’s been fixed in the C# 5 compiler.

    I suspect it’s not the optional parameter which is causing the problem here – it’s the named argument. Try removing the default values for your parameters and I suspect you’ll still have the same problem. (It’s worth differentiating between optional parameters and named arguments – they’re two separate features. They’re often used together, but certainly don’t have to be.)

    That’s the conclusion I came to when I sent this bug report to Eric and Mads:

    using System;
    
    class Test
    {
        static void Foo<T>(Func<T> func) {}
    
        static void Main()
        {
            // Works fine
            Foo(() => "hello");
    
            // Type inference fails
            Foo(func: () => "hello");
        }
    }
    

    Happily this now works in the C# 5 beta compiler.

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

Sidebar

Related Questions

Given the following Flash method: function sendToJava(name:String, ... args) { ExternalInterface.call(sendCommand, name, args); }
Given the following code snippet from inside a method; NSBezierPath * tempPath = [NSBezierPath
Given the following classes and controller action method: public School { public Int32 ID
Given the following two ways of defining a class method in Ruby: class Foo
Given the following situation (UML below), If Y has the method: public void PrintWs();
Given the following module, module Foo def bar :baz end end def send_to_foo(method) #
It seems that the following is a common method given in many tutorials on
So, given then following code type MyClass () = let items = Dictionary<string,int>() do
Given the following methods: // Method 1 void add(const std::string& header, bool replace); //Method
I have a Java method with the following signature: public <T> List<HtmlOptionsComposite> convertToHtmlOptionsCompositeList (List<?

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.