.NET - .NET Programming Concepts

Why should I learn to solve .NET: .NET Programming Concepts technical interview questions?

Learn and practise solving .NET: .NET Programming Concepts technical interview questions and answers to enhance your skills for clearing technical interviews, HR interviews, campus interviews, and placement tests.

Where can I get technical .NET: .NET Programming Concepts technical interview questions and answers with explanations?

IndiaBIX provides you with lots of fully solved .NET: .NET Programming Concepts technical interview questions and answers with a short answer description. You can download .NET: .NET Programming Concepts technical interview questions and answers as PDF files or e-books.

How do I answer .NET: .NET Programming Concepts technical interview questions from various companies?

You can answer all kinds of .NET: .NET Programming Concepts technical interview questions by practising the given exercises (short answer type). You can also find the frequently asked .NET: .NET Programming Concepts technical interview questions with answers from various companies, such as TCS, Wipro, Infosys, CTS, IBM, etc.

1.
Define variable and constant.
A variable can be defined as a meaningful name that is given to a data storage location in the computer memory that contains a value. Every variable associated with a data type determines what type of value can be stored in the variable, for example an integer, such as 100, a decimal, such as 30.05, or a character, such as 'A'.

You can declare variables by using the following syntax:

<Data_type> <variable_name> ;

A constant is similar to a variable except that the value, which you assign to a constant, cannot be changed, as in case of a variable. Constants must be initialized at the same time they are declared. You can declare constants by using the following syntax:

const int interestRate = 10;

2.
What is a data type? How many types of data types are there in .NET ?
A data type is a data storage format that can contain a specific type or range of values. Whenever you declare variables, each variable must be assigned a specific data type. Some common data types include integers, floating point, characters, and strings. The following are the two types of data types available in .NET:
  • Value type - Refers to the data type that contains the data. In other words, the exact value or the data is directly stored in this data type. It means that when you assign a value type variable to another variable, then it copies the value rather than copying the reference of that variable. When you create a value type variable, a single space in memory is allocated to store the value (stack memory). Primitive data types, such as int, float, and char are examples of value type variables.
  • Reference type - Refers to a data type that can access data by reference. Reference is a value or an address that accesses a particular data by address, which is stored elsewhere in memory (heap memory). You can say that reference is the physical address of data, where the data is stored in memory or in the storage device. Some built-in reference types variables in .Net are string, array, and object.

3.
Mention the two major categories that distinctly classify the variables of C# programs.
Variables that are defined in a C# program belong to two major categories: value type and reference type. The variables that are based on value type contain a value that is either allocated on a stack or allocated in-line in a structure. The variables that are based on reference types store the memory address of a variable, which in turn stores the value and are allocated on the heap. The variables that are based on value types have their own copy of data and therefore operations done on one variable do not affect other variables. The reference-type variables reflect the changes made in the referring variables.

Predict the output of the following code segment:

int x = 42; 
int y = 12;
int w;
object o;
o = x;
w = y * (int)o; 
Console.WriteLine(w);

/* The output of the code is 504. */

4.
Which statement is used to replace multiple if-else statements in code.
In Visual Basic, the Select-Case statement is used to replace multiple If - Else statements and in C#, the switch-case statement is used to replace multiple if-else statements.