Friday, January 3, 2014

Mostly Asked .NET Questions & Answers

 
Mostly Asked .NET Questions  & Answers
Hey I have started gathering mostly asked interview stuff and updating in this blog,it will surely benefit you, I will update this current post simultaneously with the questions as soon as I come to know.
This Post not only for interviews, it would help each programmer to clear out their concepts which they may not aware of or even think off.

* CHAR & VARCHAR DIFFERENCE..?

CHAR is used for Fixed Length Size Variable
VARCHAR is used for Variable Length Size Variable
.
EX: V.nice example to make you clear
Create table temp (City CHAR(10), Street VARCHAR(10));
Insert into temp values('Pune','Oxford'); select length(city), length(street) from temp;

Output will be: length(City) 10, Length(street)  6
Conclusion: To use storage space efficiently must use VARCHAR Instead CHAR if variable length is variable

* How does multiple if-else is replaced ?
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.

* What is the difference between Runtime and Compiletime?
Compile time
1."Compile time" is when you build your code - when the compiler converts your source code into IL.
2.The source code must be compiled into machine code in order to become and executable program.
This compilation process is referred to as compile time.
3.The terms "runtime" and "compile time" are often used by programmers to refer to different types of errors.
A compile time error is a problem such as a syntax error or missing file reference that prevents the program from successfully compiling.
The compiler produces compile time errors and usually indicates what line of the source code is causing the problem.
Runtime 
1."Runtime" is when your code is executed - for ASP.NET, when a page request is made.
2. A compiled program can be opened and run by a user. When an application is running, it is called runtime.
3.If a program's source code has already been compiled into an executable program, it may still have bugs that occur while the program is running.
Examples include features that don't work, unexpected program behavior, or program crashes.
These types of problems are called runtime errors since they occur at runtime.

EX: below will clear the difference

A compile time error is one which is detected before teh program starts running:
int i = 17;
if (i - 5)
{
}
will cause a compilation error, because "i - 5" is not a boolean vlaue - it is integer - and if conditions must be bool in C#

A run time error is one that is only detected when the program runs:
int i = 17;
int[] ar = new int[3];
ar[i] = 42;
will cause a run time error, because the value of i being used as an array index is outside the bounds of the array.
Run time errors can be trapped with a
try...catch block, compile time errors cannot.

* What is the difference between constant and readonly?
Ex:
public class ConstAndReadonlyExample
{
public const int I_CONST_VALUE = 2;
public readonly int I_RO_VALUE;
public Const_VS_Readonly()
{
I_RO_VALUE = 3;
}
}
constants values are evaluate at compile time only,Read only values will evaluate at runtime only.
const can only be initialized at the time of declaration of the field,readonly value will be initialized either declaration time or the constructor of the class allowing you to pass the value at run time.

const value can’t be changed these will be same at all the time.readonly value can be changed.

* Identifiers?
Identifiers are nothing but names given to various entities uniquely identified in a
program. The name of identifiers must differ in spelling or casing.

For example, MyProg and myProg are two different identifiers. Programming languages,such as C# and Visual Basic, strictly restrict the programmers from using any keyword as

identifiers. Programmers cannot develop a class whose name is public, because,
public is a keyword used to specify the accessibility of data in programs.

* Keywords?
Keywords are those words that are reserved to be used for a specific task. These words cannot be used as identifiers. You cannot use a keyword to define the name of a variable or method. Keywords are used in programs to use the features of object-oriented programming.
For example, the abstract keyword is used to implement abstraction and the inherits keyword is used to implement inheritance by deriving subclasses in C# and Visual Basic, respectively.

* Parameter & Arguments?
A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters.

Ex:
public void MyMethod(string myParameter) { }

string myArg1 = "this is my argument";
myClass.MyMethod(myArg1);

No comments: