VB.Net - Interview Questions and Answers

Visual Basic is a programming language that is designed especially for windows programming. VB.NET is successor of Visual Basic (VB) language and also fully integrates with .NET Framework and the Common Language Runtime, which provide language interoperability and enhanced security. Following are some selected VB.Net Interview Questions regarding Vb.Net technologies and development. Take time to review the common interview questions you will most likely to be asked.

Difference Between Assembly and DLL?

Assembly is the smallest unit of deployment of .NET applications. It is basically a file that contains the MSIL Code and Metadata. An assembly in .NET has two extensions (.exe and .dll). A .NET dll is an assembly, but .NET exe's can be assemblies as well, so it means that all .NET dlls are assemblies, but the reverse is not true. So, you can say a dll is an assembly, but an assembly may not always be a dll.

Can you use both C# and VB Project within a single Project?

No, you can't. You can not mix VB and C# within the same project. When you try to compile, it compiled without any errors and didn't complain because a VB.NET project will only actually compile the .vb files and a C# project will only actually compile the .cs files. It was ignoring the other ones, therefore you did not receive errors. You can use both C# and VB Project within a solution - have 1 proj in VB and 1 in C#.

Is VB really case insensitive?

VB is mostly case insensitive, but there are exceptions. For example, XML literals and comprehension is case sensitive.

What is the purpose of the Async keyword in VB.NET?

Async methods are intended to be non-blocking operations . The Async keyword in VB.Net is used for indicating that the lambda expression or the method that it modifies is said to be asynchronous. Such methods are called as async methods . The caller of an async method is allowed to resume its work without waiting for the async method to complete.

Is there a lock statement in VB.NET?

Yes. The SyncLock statement is the equivalent of C#'s lock statement in Vb.Net.
// C# lock (myLock) { list.Add(newItem); }
// VB SyncLock myLock list.Add(newItem) End SyncLock
The lock statement ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released.
Visual Basic Interview Questions

Difference between DirectCast() and CType() in VB.NET

DirectCast is more restrictive than CType . With CType() you can write something like Ctype("string",Integer). But with DirectCast the above statement would give a compile time error.
Dim dc As Integer = DirectCast("1", Integer) 'Gives compiler error Dim ct As Integer = CType("1", Integer) 'Will compile

What is the equivalent VB keyword for 'break'?

In both Visual Basic 6.0 and VB.NET you would use:
  1. Exit - For to break from For loop.
  2. Exit Sub - For to break from Sub.
  3. Exit Function - For to break from Function.

What is the use of Option explicit?

When Option Explicit On or Option Explicit appears in a file, variable must be compulsorily declared using the Dim or ReDim statements . While the Option Explicit is termed as OFF, variables can be used without declaration.

What is the use of shared variables in vb.net?

The "Shared" variable in VB.NET is the equivalent of the "static" variable in C#. It means that every object in the class uses the same copy of the variable, property or method. Whenever you want to have single instance of variable for your entire application, shared between objects of your class. Instead of one-per-object.

What is the difference between And and AndAlso in VB.NET?

The And operator evaluates both sides, where AndAlso operator evaluates the right side if and only if the left side is true. example
If Condition_1 And Condition_2 Then ' code here End If
Evaluates both Condition_1 and Condition_2.
If Condition_1 AndAlso Condition_2 Then ' code here End If
Evaluates Condition_2 if and only if Condition_1 is true.

How to VB.NET Single statement across multiple lines

You can use the line-continuation character (_), at the point at which you want the line to break.
cmd.sampleLine = _ "First Line" _ & "Second Line " _ & "Third Line"

What is the equivalent for C#'s '??' operator in VB.NET

The IF() operator is the equivalent for C#'s '??' operator in VB.NET. The If() operator can be called with three arguments or with two arguments.
If( [argument1,] argument2, argument3 )

How do you declare a Char literal in Visual Basic .NET?

A character literal is entered using a single character string suffixed with a C.
Dim theLetterA As Char = "A"C

How to check for a Null value in VB.NET

The equivalent of null in VB is Nothing:
If str Nothing Then ' code here End If