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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:41:51+00:00 2026-05-11T03:41:51+00:00

How good is C# type inference? I read somewhere that it’s only for local

  • 0

How good is C# type inference? I read somewhere that it’s only for local variables? Does it work for class level attributes? For method signatures? Method return types? etc.

  • 1 1 Answer
  • 3 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. 2026-05-11T03:41:51+00:00Added an answer on May 11, 2026 at 3:41 am

    There are a few main kinds of type inference in C#:

    • Implicitly typed local variables:

      • Only for local variables
      • Only when the value is assigned as part of the declaration
      • Value cannot be null
      • Value cannot be a lambda expression, anonymous method or method group (without a cast)
      • The compile-time type of the value is used for the type of the variable
      • Any further uses of the variable are only checked against the type determined by the initial declaration+assignment; they don’t contribute to the inference itself.
    • Generic method type argument inference, i.e. you don’t specify the type arguments in a call to a generic method, the compiler figures them out based on the arguments.

      • Would be really handy to have this for generic types as well as generic methods
      • Really handy anyway – LINQ would be hard or impossible to use without it
      • Anonymous types would be fairly useless without it
      • Really complicated rules, even the spec is wrong in a few places
    • Lambda expression parameter type inference

      • Compiler tries to work out the types of the parameters for lambda expressions based on the context in which it’s used
      • Usually works pretty well, in my experience
    • Array type inference, e.g. new[] { 'Hi', 'there' } instead of new string[] { 'Hi', 'there' }

      • Various small restrictions, nothing major

    I’ve probably forgotten some other features which might be called ‘type inference’. I suspect you’re mostly interested in the first, but the others might be relevant to you too 🙂

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

Sidebar

Related Questions

I'm witting a compiler and I'm searching for a library that could do type
What is a good data-type for saving hours in .net? Is it better to
I'm trying to have my application load a resource (binary file) transparently: If the
I am trying to understand Java's polymorphism, and I have one question about downcasting
I've tried the following: qDebug() << QByteArray(\x00\x10\x00\x00).size(); and i get 0 instead of 4
A UIWebView can be used to display a variety of file types (ex: a.xls
Is there an open-source library for Cocoa to create a window following iTunes' style?
I need to intersect types of incoming objects with a set of predefined ones.
Am working on a POC for self learning in which I want to keep
Assuming there are following interfaces public interface IRoot { IChildA ChildA { get; }

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.