C#’s var keyword equivalent in VB.NET

This article will explain the keyword “Dim” which is the C#’s var keyword equivalent in VB.NET .

In one of my previous blog posts , I explained about 5 things that you cannot do with a Local Type Inference in C# which explained about the use of the Var keyword in C#.

If you are looking for a var keyword in VB.NET , this blog post is for you .

The VB.NET has the keyword Dim which works similar to the var keyword in C3 for local type inference . In this case , you need to enable the Option Infer and Option Infer for the local type inference to work correctly.

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim s = "Welcome to Ginktage.com"

MessageBox.Show(s.GetType().ToString())

End Sub

End Class

 

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

How to perform Shallow Copy in C# ? by @abundantcode
To perform Shallow copy in C# , you can use the this.MemberwiseClone() method. How to perform Shall...
How to add entries to ResourceDirectory in WPF using C# ?
Below is a sample code snippet demonstrating how the entries can be added to the ResourceDirectory i...
Replacing Multiple spaces with single space in C#
Are you looking at an sample demonstrating the usage of the regular expression to replace multiple s...