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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:30:17+00:00 2026-06-07T21:30:17+00:00

I have a simple method: public static T GetValue<T>(SqlDataReader reader, int columnIndex, T defaultValue

  • 0

I have a simple method:

public static T GetValue<T>(SqlDataReader reader, int columnIndex, T defaultValue = default(T))
{
    return reader.IsDBNull(columnIndex) ? defaultValue : (T)reader[columnIndex];
}       

and usage of it:

string s = SqlUtils.GetValue<string>(reader, nameOrd);

I asked myself, why do I have to specify <string> if it’s clear from usage that type of the returned parameter is string? But apparently I have to because otherwise compiler complains The type arguments cannot be inferred from the usage.... Where is my logic fails?

  • 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-07T21:30:19+00:00Added an answer on June 7, 2026 at 9:30 pm

    Where is my logic fails?

    Nowhere. According to the specification (25.6.4 Inference of Type Arguments) the compiler does generic type inference only using arguments, not return values (I remind you that you have omitted the default value parameter in your method call and thus violating this rule). So if you want to use C#, the specification simply tells you that generic type inference is not possible with return types only. Or simply use some other CLS language which allows this. C# doesn’t.

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

Sidebar

Related Questions

I defined this simple method: public static boolean isBorder(int x, int y) throws CollisionDetectionException
I have a very simple extension method that looks like this: public static string
I have a simple static method : public static <U> U findStuff(String id) {
I have simple method in C# : public static string BetweenOf(string ActualStr, string StrFirst,
So I have a simple method called Invert : public static void Invert(this bool
Suppose I have a simple method like this for processing two lists: public static
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
I have only simple data types in method signature of service (such as int,
Let's say I have this method: public static object CallMethod(Delegate method, params object[] args)
I have a simple Class package chapter10; public class CompilationTest { public static void

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.