Declaration Statements in VB.NET

Posted on

Declaration Statements

The declaration statements are used to name and define procedures, variables, properties, arrays, and constants. When you declare a programming element, you can also define its data type, access level, and scope.

The programming elements you may declare include variables, constants, enumerations, classes, structures, modules, interfaces, procedures, procedure parameters, function returns, external procedure references, operators, properties, events, and delegates.

Following are the declaration statements in VB.Net:

S.N Statements and Description Example
1 Dim Statement
Declares and allocates storage space for one or more variables.
Dim number As IntegerDim quantity As Integer = 100Dim message As String = “Hello!”
2 Const Statement
Declares and defines one or more constants.
Const maximum As Long = 1000Const naturalLogBase As Object = CDec(2.7182818284)
3 Enum Statement
Declares an enumeration and defines the values of its members.
Enum CoffeeMugSize    Jumbo    ExtraLarge    Large    Medium    SmallEnd Enum
4 Class Statement
Declares the name of a class and introduces the definition of the variables, properties, events, and procedures that the class comprises.
Class BoxPublic length As DoublePublic breadth As Double   Public height As DoubleEnd Class
5 Structure Statement
Declares the name of a structure and introduces the definition of the variables, properties, events, and procedures that the structure comprises.
Structure BoxPublic length As Double           Public breadth As Double   Public height As DoubleEnd Structure
6 Module Statement
Declares the name of a module and introduces the definition of the variables, properties, events, and procedures that the module comprises.
Public Module myModuleSub Main()Dim user As String = InputBox(“What is your name?”) MsgBox(“User name is” & user)End Sub End Module
7 Interface Statement
Declares the name of an interface and introduces the definitions of the members that the interface comprises.
Public Interface MyInterface    Sub doSomething()End Interface
8 Function Statement
Declares the name, parameters, and code that define a Function procedure.
Function myFunction(ByVal n As Integer) As Double     Return 5.87 * nEnd Function
9 Sub Statement
Declares the name, parameters, and code that define a Sub procedure.
Sub mySub(ByVal s As String)    ReturnEnd Sub
10 Declare Statement
Declares a reference to a procedure implemented in an external file.
Declare Function getUserNameLib “advapi32.dll” Alias “GetUserNameA” (  ByVal lpBuffer As String,   ByRef nSize As Integer) As Integer
11 Operator Statement
Declares the operator symbol, operands, and code that define an operator procedure on a class or structure.
Public Shared Operator +(ByVal x As obj, ByVal y As obj) As obj        Dim r As New obj’ implemention code for r = x + y        Return r    End Operator
12 Property Statement
Declares the name of a property, and the property procedures used to store and retrieve the value of the property.
ReadOnly Property quote() As String     Get         Return quoteString    End Get End Property
13 Event Statement
Declares a user-defined event.
Public Event Finished()
14 Delegate Statement
Used to declare a delegate.
Delegate Function MathOperator(     ByVal x As Double,     ByVal y As Double ) As Double


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:


interview questions of dot net

Posted on

Qu – What are Cascading style sheets?

Cascading style sheets(CSS) collect and organize all of the formatting information applied to HTML elements on a Web form. Because they keep this information in a single location, style sheets make it easy to adjust the appearance of Web applications.


Qu – What is the difference between System.String and System.Text.StringBuilder classes?

System.String is immutable.
System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.


Qu – What are different types of Assemblies?

  • Single file and multi file assembly.
  • Assemblies can be static or dynamic.
  • Private assemblies and shared assemblies.


Qu – What is Delegates?

Delegates are a type-safe, object-oriented implementation of function pointers and are used in many situations where a component needs to call back to the component that is using it. Delegates are generally used as basis of events, which allow any delegate to easily be registered for as event.


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:



interview questions of dot net

Posted on

Qu – What is the difference between a private assembly and a shared assembly?

  • Location and visibility

: A private assembly is normally used by a single application, and is stored in the application’s directory, or a sub -directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. the .NET framework classes.

  • Versioning: The runtime enforces versioning constraints only on shared assemblies, not on private assemblies.


Qu – What is garbage collection?

Garbage collection is a heap -management strategy where a run-time component takes responsibility for managing the lifetime of the memory used by objects. This concept is not new to .NET-Java and many other languages/runtimes have used garbage collection for some time.


Qu -What is the difference between an event and a delegate?

An event is just a wrapper for a multicast delegate. Adding a public event to a class is almost the same as adding a public multicast delegate field. In both cases, subscriber objects can register for notifications, and in both cases the publisher object can send notifications to the subscribers. However, a public multicast delegate has the undesirable property that external objects can invoke the delegate, something we’d normally want to re

strict to the publisher. Hence events – an event adds public methods to the containing

class to add and remove receivers, but does not make the invocation mechanism public.


Qu- What size is a .NET object?

Each instance of a reference type has two fields maintained by the runtime -a method table pointer and a sync block. These are 4 bytes each on a 32-bit system, making a total of 8 bytes per object overhead. Obviously the instance data for the type must be added to this to get the overall size of the obj ect. So, for example, instances of the following class are 12 bytes each:


class MyInt


private int x;


However, note that with the current implementation of the CLR there seems to be a minimum object size of 12 bytes, even for classes with no data (e.g.System.Object).

Values types have no equivalent overhead.


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:

interview questions of dot net

Posted on

1.)  What is an Object?

Object is an instance of a class; it contains real values instead of variables. For example, let’s create an instance of class Employee called “John”.

Employee John= new Employee ();

Now we can access all the methods in the class “Employee” via object “John” as shown below.

John.setName (“XYZ”);


2.) What are the Access Modifiers in C#?

Different Access Modifier are – Public, Private, Protected, Internal, Protected Internal

  • Public – When a method or attribute is defined as Public, It can be accessed from any code in project. For example in the above Class “Employee”, getName(), setName() etc are public.
  • Private – When a method or attribute is defined as Private, It can be accessed by any code within the containing type only. For example in the above Class “Employee”, attributes name and salary can be accessed with in the Class Employee Only. If an attribute or class is defined without access modifiers, its default access modifier will be private.
  • Protected – When an attribute and methods are defined as protected, it can be accessed by any method in inherited classes and any method within the same class. The protected access modifier cannot be applied to class and interfaces. Methods and fields in an interface cannot be declared protected.
  • Internal – If an attribute or method is defined as Internal , Access is restricted to classes within the current project assembly
  • Protected Internal – If an attribute or method is defined as Protected Internal, Access is restricted to classes within the current project assembly and types derived from the containing class.


3.) Define Static Members in C#?

  • If an attributes value had to be same across all the instances of the same class, static keyword is used. For example if the Minimum salary should be set for all employees in the employee class, use the following code


private static double MinSalary = 30000;


To access a private or public attributes or methods in a class, at first an object of the class should be created. Then using that instance of class, attributes or methods can be accessed. To access a static variable, we don’t want to create an instance of the class having the static variable. We can directly refer that static variable as shown below.

double var = Employee.MinSalary ;


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:



interview questions of dot net

Posted on

Qu.) Difference between stored procedure and function


1) Procedure can return zero or n values whereas function can return one value which is mandatory.
2) Procedures can have input, output parameters for it whereas functions can have only input parameters.
3) Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
4) Functions can be called from procedure whereas procedures cannot be called from function.
5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
6) We can go for transaction management in procedure whereas we can’t go in function.
7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.


Qu.)  Difference between Abstract and Interface

Ans.) Abstract Class:
-Abstract class provides a set of rules to implement next class
-Rules will be provided through abstract methods
-Abstract method does not contain any definition
-While inheriting abstract class all abstract methods must be override
-If a class contains at least one abstract method then it must be declared as an “Abstract Class”
-Abstract classes cannot be instantiated (i.e. we cannot create objects), but a reference can be created
-Reference depends on child class object’s memory
-Abstract classes are also called as “Partial abstract classes”
-Partial abstract class may contain functions with body and functions without body
-If a class contains all functions without body then it is called as “Fully Abstract Class” (Interface)

-If a class contains all abstract methods then that class is known as “Interface”
-Interfaces support like multiple inheritance
-In interface all methods r public abstract by default
-Interfaces r implementable
-Interfaces can be instantiated, but a reference cannot be created



Qu.)What are differences between Array list and Hash table?


1) Hash table store data as name, value pair. While in array only value is store.

2) To access value from hash table, you need to pass name. While in array, to access value, you need to pass index number.

3) you can store different type of data in hash table, say int, string etc. while in array you can store only similar type of data.


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:

Qu.) What is CSS? Explain inline and embedded CSS.

Posted on

Ans.)   CSS stands for Cascading Style Sheets


Styles define how to display HTML elements

Styles were added to HTML 4.0 to solve a problem

External Style Sheetscan save a lot of work

External Style Sheets are stored in CSS files



Inline Styles

An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly.

To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:


<p style=”color:sienna;margin-left:20px”>This is a paragraph.</p>



Internal or Embedded Style Sheet

An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

<head> <style> hr {color:sienna;} p {margin-left:20px;} body {background-image:url(“images/back40.gif”);} </style> </head>


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -:


Posted on


  • Delegates in C# are used for Event Handling.  Delegates are useful for two main reasons:

First, delegates support events. Second, delegates give your program a way to execute

Methods at runtime without having to know precisely what those methods are at compile time.



  • An important C# feature is built upon the foundation of delegates: the event.
  • An event is, essentially, an automatic notification that some action has occurred. Events work like this:  An object that has an interest in an event registers an event handler for that event.
  • When the event occurs, all registered handlers are called. Event handlers are represented by delegates. Events are members of a class and are declared using the event keyword.


Its most commonly used form is shown here:

  • event event-delegate event-name;

Here, event-delegate is the name of the delegate used to support the event, and event name is the name of the specific event object being declared.


A simple example:

using System;

// Declare a delegate type for an event.

delegate void MyEventHandler();

// Declare a class that contains an event.

class MyEvent {

public event MyEventHandler SomeEvent;

// This is called to raise the event.

public void OnSomeEvent() {

if(SomeEvent != null)




class EventDemo {

// An event handler.

static void Handler() {

Console.WriteLine(“Event occurred”);


static void Main() {

MyEvent evt = new MyEvent();

// Add Handler() to the event list.

evt.SomeEvent += Handler;

// Raise the event.






Event occurred


Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: