I can create a new object like this:
Dim sqlconn As New SqlClient.SqlConnection(cs)
or like this:
Dim sqlconn = New SqlClient.SqlConnection(cs)
What's the difference? Since both worked fine for me!
The main difference between classes and modules is that classes can be instantiated as objects while standard modules cannot.
Sub New() is the constructor of your class, which is executed to initialize an instance of the class. You can't call it after the object has been created.
<> in VB.NET means "not equal to". It can be used with the normal oprands as well as in comparision with the items when compared with the datas fetched with the data reader (from database). Follow this answer to receive notifications.
The first one is the short form of:
Dim sqlconn As SqlClient.SqlConnection = New SqlClient.SqlConnection(cs)
The second one depends on what version of VB you are using. In VB 7 and VB 8 it is the same as:
Dim sqlconn As Object = New SqlClient.SqlConnection(cs)
In VB 9 type inference was introduced, so the compiler will infer the type from the assignment and produce the same code as the first one.
The type inference requires that the option Option Infer
is set to on
. This is the default setting, but it might be off if you migrate a project from an older version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With