Results 1 to 4 of 4

Thread: Use of var keyword in C#

  1. #1

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Use of var keyword in C#

    While learning any new language seems best to dig into "why this way" or "pitfalls over this or that". The var keyword was one of those that needed exploring and thought the following link was a good discussion.

    StackOverflow Use of var keyword in C#

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Use of var keyword in C#

    Similar can be achieved with Option Infer in VB ... that said, if you know what the type of a variable is and always will be then type inference is probably not best practice.

  3. #3

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: Use of var keyword in C#

    Quote Originally Posted by Merrion View Post
    Similar can be achieved with Option Infer in VB ... that said, if you know what the type of a variable is and always will be then type inference is probably not best practice.
    Thanks for chiming in although if one takes the time to read the thread it goes beyond this (Option Infer etc) yet also does address it.

  4. #4
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Use of var keyword in C#

    I use type inference for example with generic interfaces and we have to use it for LINQ (or anything that returns anonymous types). However I crashed into the same issue this poster has in that I only want type inference for some of my generic params...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width