Monday, March 10, 2014

Asp .net Interview Que

Que:- What is a IL?
Ans:-(IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language)(Common Intermediate Language). All .NET source code is compiled to IL. This IL is converted to machine code at the point where the software is installed, or at run-time by a Just In Time (JIT) compiler.

Que:- What is a CLR?
Ans: Full form of CLR is Common Language Runtime and it forms the heart of the .NET frame All Languages have runtime and its the responsibility of the runtime to take care of the execution of the program. For example VC++ has MSCRT40.DLL,VB6 has MSVBVM60.Java has Java Virtual Machine etc. Similarly .NET has CLR. Following are the responsibility CLR Garbage Collection :- CLR automatically manages memory thus eliminating memory leaks. When objects are not referred GC automatically releases thosememories thus providing efficient memory management.Code Access Security :- CAS grants rights to program depending on the securiconfiguration of the machine. Example the program has rights to edit or creata new file but the security configuration of machine does not allow the prograto delete a file. CAS will take care that the code runs under the environment omachines security configuration.Code Verification :- This ensures proper code execution and type safety whilethe code runs. It prevents the source code to perform illegal operation such asaccessing invalid memory locations etc.IL( Intermediate language )-to-native translators and optimizer’s :- CLR usesJIT and compiles the IL code to machine code and then executes. CLR alsodetermines depending on platform what is optimized way of running the IL code.

Oue:- What is a CLS(Common Language Specification)?
Ans:- This is a subset of the CTS which all .NET languages are expected to support. It was always a dream of Microsoft to unite all different languages in to one umbrella and CLS is one step towards that. Microsoft has defined CLS which are nothing but guidelines that language to follow so that it can communicate with other .NET languages in a seamless manner.

Que:- What is a Managed Code?
Ans:- Managed code runs inside the environment of CLR i.e. .NET runtime. In short all IL are managed code. But if you are using some third party software example VB6 or VC++ component they are unmanaged code as .NET runtime (CLR) does not have control over the source code execution of the language.

Que:- What is a Assembly?
Ans:-

  1. Assembly is unit of deployment like EXE or a DLL.
  2. An assembly consists of one or more files (dlls, exe’s, html files etc.), andrepresents a group of resources, type definitions, and implementations of thosetypes. An assembly may also contain references to other assemblies. Theseresources, types and references are described in a block of data called a manifest.The manifest is part of the assembly, thus making the assembly self-describing.
  3. An assembly is completely self-describing.An assembly contains metadatainformation, which is used by the CLR for everything from type checking andsecurity to actually invoking the components methods. As all information is in theassembly itself, it is independent of registry. This is the basic advantage ascompared to COM where the version was stored in registry.
Que:- What are the different types of Assembly?
Ans:- There are two types of assembly Private and Public assembly. 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. Crystal report classes which will be used by all application forReports.

Que:- What is NameSpace?
Ans:- Namespace has two basic functionality :-NameSpace Logically group types, example System.Web.UI logically groupsour UI related features.In Object Oriented world many times its possible that programmers will use thesame class name.By qualifying NameSpace with classname this collision is able tobe removed.

Que: What is Difference between NameSpace and Assembly?
Ans:- Following are the differences between namespace and assembly :Assembly is physical grouping of logical units. Namespace logically groupsclasses.Namespace can span multiple assembly.

Que:- What is garbage collection?
Ans:- Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding ..... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed whenit goes out of the scope of a function. Therefore, we should not put code into a class destructor to release resources.

Que:- What is reflection?
Ans:- All .NET assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as “Reflection”.System. Reflection can be used to browse through the metadata information. Using reflection you can also dynamically invoke methods using System.Type.Invokemember. Below is sample source code.Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.LoadDim Pobjtype As TypeDim PobjObject As ObjectDim PobjButtons As New Windows.Forms.Button()Pobjtype = PobjButtons.GetType()For Each PobjObject In Pobjtype.GetMembersLstDisplay.Items.Add(PobjObject.ToString())NextEnd SubEnd Class

Que:- What are Value types and Reference types ?
Ans:- Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure.Reference types store a reference to the value's memory address, and are allocated on the heap.Reference types can be self-describing types, pointer types, or interface types.Variables that are value types each have their own copy of the data, and therefore operations onone variable do not affect other variables. Variables that are reference types can refer to the sameobject; therefore, operations on one variable can affect the same object referred to by anothervariable. All types derive from the System.Object base type.

Most Important Question.

Que:- What is the difference between VB.NET and C# ?
Ans:- Well this is the most debatable issue in .NET community and people treat there languages like religion. Its a subjective matter which language is best. Some like VB.NET’s natural style and some like professional and terse C# syntaxes. Both use the same framework and speed is also very much equivalents. But still let’s list down some major differences between them :-
Advantages VB.NET :-* Has support for optional parameters which makes COM interoperability much easy.* With Option Strict off late binding is supported.Legacy VB functionalities can beused by using Microsoft.VisualBasic namespace.* Has the WITH construct which is not in C#.* The VB.NET part of Visual Studio .NET compiles your code in the background.While this is considered an advantage for small projects, people creating very large projects have found that the IDE slows down considerably as the project gets larger.
Advantages of C#* XML documentation is generated from source code but this is now been incorporatedin Whidbey.* Operator overloading which is not in current VB.NET but is been introduced inWhidbey.* Use of this statement makes unmanaged resource disposal simple.* Access to Unsafe code. This allows pointer arithmetic etc, and can improveperformance in some situations. However, it is not to be used lightly, as a lot of the normal safety of C# is lost (as the name implies).This is the major difference that you can access unmanaged code in C# and not in VB.NET.

Que:- What is the difference between System exceptions and Application exceptions?
Ans:- All exception derives from Exception Base class. Exceptions can be generated programmatically or can be generated by system. Application Exception serves as the base class for all application- specific exception classes. It derives from Exception but does not provide any extended functionality. You should derive your custom application exceptions from Application Exception. Application exception is used when we want to define user defined exception, while system exception is all which is defined by .NET.

Que:- What is the difference between Convert.toString and .toString()method ?
Ans:- Just to give an understanding of what the above question means seethe below code.int i =0;MessageBox.Show(i.ToString());MessageBox.Show(Convert.ToString(i));We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what’s the difference.The basic difference between them is “Convert” function handles NULLS while “i.ToString()”does not it will throw a NULL reference exception error. So as good coding practice using“convert” is always safe.