Top 19 Dot-net Developer Interview Questions
Q1. What Is An Identifier?
Identifiers are northing but names given to diverse entities uniquely identified in a program. The call of identifiers should vary in spelling or casing. For instance, MyProg and myProg are two distinctive identifiers. Programming languages, consisting of C# and Visual Basic, strictly restrict the programmers from using any keyword as identifiers. Programmers cannot expand a category whose name is public, because, public is a key-word used to specify the accessibility of facts in programs.
Q2. What Does A Break Statement Do In The Switch Statement?
The transfer announcement is a ramification control statement this is used to handle more than one choices and trfer manage to the case statements within its body.
The following code snippet indicates an instance of using the switch assertion in C#:
switch(choice)
case 1:
console.WriteLine("First");
ruin;
case 2:
console.WriteLine("Second");
damage;
default:
console.WriteLine("Wrong preference");
smash;
In transfer statements, the spoil statement is used at the stop of a case assertion. The break assertion is obligatory in C# and it avoids the autumn via of 1 case statement to some other.
Q3. Give The Syntax Of Using The For Loop In C# Code?
The syntax of the usage of the for loop in C# code is given as follows:
for(initializer; situation; loop expression)
//statements
In the preceding syntax, initializer is the preliminary value of the variable, condition is the expression that is checked earlier than the execution of the for loop, and loop expression either increments or decrements the loop counter.
The instance of using the for loop in C# is shown within the following code snippet:
for(int i = zero; i < five; i++)
Console.WriteLine("Hello");
In the previous code snippet, the word Hello might be displayed for 5 times in the output window.
Q4. What Is A Data Type? How Many Types Of Data Types Are There In .Net ?
A data type is a facts storage format which can include a specific type or variety of values. Whenever you declare variables, each variable should be assigned a particular information type. Some commonplace records kinds include integers, floating point, characters, and strings.
The following are the two styles of information sorts available in .NET:
• Value kind - Refers to the facts type that carries the facts. In different words, the precise price or the records is without delay stored in this information type. It me that whilst you assign a price kind variable to any other variable, then it copies the value rather than copying the reference of that variable. When you create a cost kind variable, a unmarried space in memory is allocated to store the price (stack memory). Primitive facts types, which include int, go with the flow, and char are examples of cost type variables.
• Reference kind - Refers to a statistics kind that could access information by using reference. Reference is a cost or an address that accesses a selected statistics by address, which is stored somewhere else in memory (heap reminiscence). You can say that reference is the bodily cope with of facts, where the facts is saved in reminiscence or within the storage device. Some integrated reference types variables in .Net are string, array, and item.
Q5. What Are The Different Types Of Literals?
A literal is a textual representation of a particular price of a kind.
The unique varieties of literals in Visual Basic are:
Boolean Literals - Refers to the True and False literals that map to the real and fake country, respectively.
Integer Literals - Refers to literals that may be decimal (base 10), hexadecimal (base sixteen), or octal (base eight).
Floating-Point Literals - Refers to an integer literal observed by an non-obligatory decimal point By default, a floating-point literal is of kind Double.
String Literals - Refers to a series of 0 or greater Unicode characters starting and finishing with an ASCII double-quote individual.
Character Literals - Represents a single Unicode individual of the Char type.
Date Literals - Represents time expressed as a value of the Date kind.
Nothing - Refers to a literal that does not have a kind and is convertible to all sorts inside the type gadget.
The exclusive kinds of literals in C# are:
Boolean literals - Refers to the True and False literals that map to the genuine and fake states, respectively.
Integer literals - Refers to literals that are used to jot down values of sorts int, uint, lengthy, and ulong.
Real literals - Refers to literals that are used to write values of types flow, double, and decimal.
Character literals - Represents a single individual that typically includes a man or woman in fees, together with 'a'.
String literals - Refers to string literals, which may be of two kinds in C#:
A everyday string literal consists of zero or greater characters enclosed in double prices, inclusive of "howdy".
A verbatim string literal includes the @ character accompanied by means of a double-quote individual, together with @"whats up".
The Null literal - Represents the null-kind.
Q6. Briefly Explain The Characteristics Of Value-kind Variables That Are Supported In The C# Programming Language.?
The variables which can be primarily based on cost types at once comprise values.
The traits of cost-type variables that are supported in C# programming language are as follows:
All value-kind variables derive implicitly from the System.ValueType magnificence
You cannot derive any new kind from a value type
Value types have an implicit default constructor that initializes the default fee of that type
The fee type consists of major classes:
Structs - Summarizes small companies of related variables.
Enumerations - Consists of a fixed of named constants.
Q7. Differentiate Between Boxing And Unboxing.?
When a cost type is transformed to an item kind, the procedure is called boxing; whereas, when an object type is transformed to a fee kind, the method is known as unboxing.
Boxing and unboxing allow cost sorts to be treated as items. Boxing a value kind programs it inside an example of the Object reference kind. This allows the fee type to be saved on the rubbish amassed heap. Unboxing extracts the fee kind from the object. In this situation, the integer variable i is boxed and assigned to object obj.
Example:
int i = 123;
object obj = i; /* Thi line packing containers i. */
/* The object obj can then be unboxed and assigned to integer variable i: */
i = (int)obj; // unboxing
Q8. Mention The Two Major Categories That Distinctly Classify The Variables Of C# Programs.?
Variables which might be defined in a C# program belong to two major classes: cost type and reference type. The variables which are based on cost type incorporate a value this is either allotted on a stack or allocated in-line in a structure. The variables which can be based totally on reference types save the reminiscence cope with of a variable, which in flip shops the fee and are allotted at the heap. The variables which can be based totally on fee kinds have their very own reproduction of information and consequently operations executed on one variable do now not affect other variables. The reference-type variables replicate the adjustments made within the referring variables.
Predict the output of the subsequent code section:
int x = forty two;
int y = 12;
int w;
item o;
o = x;
w = y * (int)o;
Console.WriteLine(w);
/* The output of the code is 5@*/
Q9. What Is The Difference Between Constants And Read-best Variables That Are Used In Programs?
Constants perform the equal obligations as study-most effective variables with some differences. The differences between constants and study-simplest are
Constants:
Constants are dealt with at assemble-time.
Constants supports value-type variables.
Constants ought to be used whilst it's miles very unlikely that the price will ever exchange.
Read-simplest:
Read-best variables are evaluated at runtime.
Read-most effective variables can preserve reference kind variables.
Read-best variables need to be used whilst run-time calculation is needed.
Q10. Explain Keywords With Example.?
Keywords are those words which are reserved to be used for a selected mission. These words can't be used as identifiers. You can't use a keyword to define the call of a variable or method. Keywords are utilized in applications to use the functions of object-orientated programming.
For example, the abstract keyword is used to implement abstraction and the inherits keyword is used to enforce inheritance by using deriving subclasses in C# and Visual Basic, respectively.
The new keyword is universally used in C# and Visual Basic to enforce encapsulation by growing gadgets.
Q11. What Is A Parameter? Explain The New Types Of Parameters Introduced In C# four.Zero.?
A parameter is a special kind of variable, that is utilized in a feature to provide a chunk of data or input to a caller characteristic. These inputs are referred to as arguments.
In C#, the exclusive kinds of parameters are as follows:
Value kind - Refers that you do no longer need to offer any key-word with a parameter.
Reference kind - Refers which you need to mention the ref key-word with a parameter.
Output kind - Refers which you want to mention the out keyword with a parameter.
Optional parameter - Refers to the brand new parameter added in C# 4.@It allows you to forget about the parameters which have a few predefined default values.
The example of optionally available parameter is as follows:
public int Sum(int a, int b, int c = 0, int d = 0); /* c and d is elective */
Sum(10, 20); //10 + 20 + 0 + zero
Sum(10, 20, 30); //10 + 20 + 30 + 0
Sum(10, 20, 30, forty); //10 + 20 + 30 + 40
• Named parameter - Refers to the brand new parameter brought in C# 4.@Now you may offer arguments via call in place of role.
The instance of the named parameter is as follows:
public void CreateAccount(string name, string cope with = "unknown", int age = 0);
CreateAccount("Sara", age: 30);
CreateAccount(deal with: "India", call: "Sara");
Q12. Briefly Explain The Characteristics Of Reference-kind Variables That Are Supported In The C# Programming Language.?
The variables that are based on reference sorts keep references to the real records.
The key phrases that are used to claim reference kinds are:
Class - Refers to the primary constructing block for the programs, which is used to encapsulate variables and techniques right into a single unit.
Interface - Contains most effective the signatures of techniques, houses, occasions, or indexers.
Delegate - Refers to a reference kind that is used to encapsulate a named or nameless method.
Q13. Differentiate Between The While And For Loop In C#.?
The at the same time as and for loops are used to execute the ones units of code that need to be time and again finished, unless the end result of the required condition evaluates to fake. The only difference between the two is of their syntax. The for loop is outstanding by way of putting an express loop variable.
Q14. Give The Syntax Of Using The While Loop In A C# Program.?
The syntax of the usage of the even as loop in C# is:
while(circumstance) //circumstance
//statements
You can locate an example of using the whilst loop in C#:
int i = 0;
whilst(i < five)
Console.WriteLine("zero ", i);
i++;
The output of the preceding code is: 0 1 2 three four .
Q15. Determine The Output Of The Code Snippet.?
Int a = 29;
a--;
a -= ++a;
Console.WriteLine("The fee of a is: 0", a);
/* The output of the code is -@*/
Q16. Which Statement Is Used To Replace Multiple If-else Statements In Code.?
In Visual Basic, the Select-Case announcement is used to update a couple of If - Else statements and in C#, the transfer-case declaration is used to update a couple of if-else statements.
Q17. Define Variable And Constant.?
A variable can be described as a significant name this is given to a facts storage location inside the computer reminiscence that includes a value. Every variable associated with a statistics type determines what kind of value may be saved inside the variable, as an instance an integer, such as a hundred, a decimal, which include 30.05, or a man or woman, consisting of 'A'.
You can declare variables by using the use of the subsequent syntax:
<Data_type> <variable_name> ;
A constant is similar to a variable besides that the cost, that you assign to a regular, cannot be modified, as in case of a variable. Constants ought to be initialized at the identical time they're declared. You can declare constants through using the subsequent syntax:
const int interestRate = 10;
Q18. What Is The Syntax To Declare A Namespace In .Internet?
In .NET, the namespace key-word is used to declare a namespace inside the code.
The syntax for putting forward a namespace in C# is:
namespace UserNameSpace;
The syntax for asserting a namespace in VB is:
Namespace UserNameSpace
Q19. What Is The Main Difference Between Sub-process And Function?
The sub-technique is a block of more than one visible primary statements inside Sub and End Sub statements. It is used to perform sure duties, together with changing residences of items, receiving or processing records, and displaying an output. You can outline a sub-procedure anywhere in a software, consisting of in modules, structures, and instructions.
We can also offer arguments in a sub-system; but, it does now not go back a brand new price.
The function is likewise a set of statements inside the Function and End Function statements. It is much like sub-procedure and plays the equal undertaking. The predominant difference between a function and a sub-system is that sub-methods do not go back a price even as capabilities do.
