
Originally Posted by
FunkyDexter
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.