Avonelle's Blog

Why would I set Option Infer to Off?

By Avonelle Lovhaug on 2/21/2021

I had completely forgotten about the Option Infer feature in Visual Basic, but noticed it the other day when I was checking some other settings.

nt" target="_blank">Option Infer feature in Visual Basic, but noticed it the other day when I was checking some other settings.

 

By default, Option Infer is set to Off. What happens when you change it to On?

Option Infer On allows you to declare local variables without explicitly identify the data type. This means that if you add code like this:

Dim abc = 5

It knows that the variable is an Integer. With Option Infer Off, it would assume it is an Object.

To me, I don’t see a lot of point in using Option Infer Off at this point. I assume that it was intended for people switching from class Visual Basic to VB.NET, but at this point, are there many people doing that?

VB.NET
Programming