Results 1 to 19 of 19

Thread: Hi im new

Threaded View

  1. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Hi im new

    Quote Originally Posted by FunkyDexter View Post
    Option Infer allows you to declcare a variable and have it's type "inferred" from the value you first give it. E.g. Dim i = 12 will infer that i is an integer as opposed to having to say Dim i as Integer = 12. You should have this one switched off.
    I do not agree with that point. I think Option Infer should be On, I use it all the time. Not for simple things like Dim i = 12, but when you go into LINQ you really need it. I also use it in the cases where an object is constructed for you:
    Code:
    Using stream = tcpClient.GetStream()
     '...
    End Using
    
    'Instead of:
    Using stream As NetworkStream = tcpClient.GetStream()
      '...
    End Using
    I also use it when I need to cast an object:
    Code:
    Dim item = DirectCast(ListBox1.Items(0), MyCustomListItemObject)
    When using the above it feels really repetitive to have to type:
    Code:
    Dim item As MyCustomListItemObject = DirectCast(ListBox1.Items(0), MyCustomListItemObject)
    This is however a matter of style and I think the OP can decide for himself which style that will fit him in the future and that's the reason I don't think you should tell a new user that this option should be turned off since you then deny him his right to make up his own mind about it. Turning Option Strict On is another matter since it forces you to learn best practices which is a good thing.
    Last edited by Joacim Andersson; May 24th, 2013 at 07:17 AM.

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