TYBSc(CS)

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 -: http://www.vissicomp.com

Advertisements

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 -: http://www.vissicomp.com

 

 

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 -: http://www.vissicomp.com

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 -: http://www.vissicomp.com

 

 

interview questions of dot net

Posted on Updated on

    1.  When an .aspx page is requested from the web server, the out put will be rendered to browser in             following format.

  • HTML
  • XML
  • WML
  • JSP

    2.   The first event to be triggered in an aspx page is

  • Page_Load()
  • Page_Init()
  • Page_click()
  • Page_close()

3.    Common language specification (CLS)

  • A.is an execution engine for all .NET applications.
  • B.is similar to JVM as in Java.
  • defines standard rules for defining .NET compliant languages.
  • is a compiler

4.    Common Type Structure (CTS)

  • defines data types in order to be run by CLR.
  • defines a set of rules for all compilers to generate managed code for .NET.
  • describes a set of features that different languages have in common.
  • All of the above.
  • None of the above

5.   Which of the following statements is correct about Managed Code?

  • Managed code is the code that is compiled by the JIT compilers.
  • Managed code is the code where resources are Garbage Collected.
  • Managed code is the code that is written to target the services of the CLR.
  • Managed code is the code that runs on top of Windows.
  • Managed code is the code that can run on top of Linux.

6.  Which of the following jobs are performed by Garbage Collector?

  • Managing memory leaks
  • Releasing memory on the stack
  • Managing database collections
  • Closing unclosed files

 

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com