Thursday, August 1, 2019

.NET Interview Questions !!!

Q) .net vs java
FeatureMS .NetJava/JEE
Operating SystemWindowsMultiple OS
Common Language RuntimeCommon Language RuntimeJava Virtual Machine
XMLSystem XMLJava API for XML Processing
NamingJava Naming and Directory InterfaceActive Directory Service Interfaces
HTTP EngineInternet Information ServicesApplication Servers from various vendors
Server Components.Net, COM+ServicesEnterprise Java Beans

Q1) What is the relation between Classes and Objects?
Class applies to a type or model of a GROUP of itedot-ms, objects, or concepts.
Object applies to a specific material item or concept, a group of which may comprise a class.
Q2) What is an IL?
(IL) Intermediate Language is also known as MSIL is MicroSoft Intermediate Language or Common Language Runtime (CLR) . When we compile .Net applications, its complied to MSIL, which is not machine read language. Hence Common Language Runtime (CLR) with JustIn Time Complier (JIT) , converts this MSIL to native code (binary code) , which is machine language.
Q3) What are the defining traits of an object-oriented language?
The defining traits of an object-oriented language are:
  • Inheritance
  • Abstraction
  • Encapsulation
  • Polymorphism
1. Inheritance: The main class or the root class is called as a Base Class. Any class which is expected to have ALL properties of the base class along with its own is called as a Derived class. The process of deriving such a class is Derived class.
2. Abstraction: Abstraction is creating models or classes of some broad concept. Abstraction can be achieved through Inheritance or even Composition.
3. Encapsulation: Encapsulation is a collection of functions of a class and object. The “Food” class is an encapsulated form. It is achieved by specifying which class can use which members (private, public, protected) of an object.
4. Polymorphism: Polymorphism means existing in different forms. Inheritance is an example of Polymorphism. A base class exists in different forms as derived classes. Operator overloading is an example of Polymorphism in which an operator can be applied in different situations.
Q4) What is the concept of DISPOSE method?
DISPOSE method belongs to IDisposable interface. It is used to free unmanaged resources like files, network connection etc. It manages and handles this by an instance of the class that implements this interface. Dispose methods must be called explicitly and hence the any object using IDisposable must also implement finalizer to free resources in situations wherein Dispose is not called. Multiple calls to dispose method must be ignored when called once. The objects disposable methods must be called in the order of containment.
Q5) What is a CLR?
The Common Language Runtime (CLR) is a core component of .NET framework. It is Microsoft’s implementation of the Common Language Infrastructure (CLI) standard, which defines an execution environment for program code. In the CLR, code is expressed in a form of bytecode called the Common Intermediate Language (CIL) . Developers using the CLR write code in a language such as C# or VB.NET. At compile time, the .NET compiler converts such code into CIL code. At runtime, the CLR’s just-in-time compiler converts the CIL code into code native to the operating system. Alternatively, the CIL code can be compiled to native code in a separate step prior to runtime by using the Native Image Generator (NGEN) . This speeds up all later runs of the software as the CIL-to-native compilation is no longer necessary.
During the execution of the program, the Common Language Runtime (CLR) manages memory, Thread execution, Garbage Collection (GC) , Exception Handling, Common Type System (CTS) , code safety verifications, and other system services. The Common Language Runtime (CLR) environment is also referred to as a managed environment, because during the execution of a program it also controls the interaction with the Operating System.
Q6) What is CTS?
CTS stands for Common Type System. The CTS makes available a common set of data types so that compiled code of one language could easily interoperate with compiled code of another language by understanding each others’ data types. If two languages (c# or vb.net or j# or vc++) want to communicate with each other, they have to convert into some common type (i.e. in COMMON LANGUAGE RUNTIME) . In C# we use int which is converted to Int32 of CLR to communicate with vb.net which uses Integer or vice versa.
Q7) What is a CLS (Common Language Specification)?
CLS is a specification that defines the rules to support language integration. This is done in such a way, that programs written in any language (.NET compliant) can communicate with one another. This also can take full advantage of inheritance, polymorphism, exceptions, and other features. This is a subset of the CTS, which all .NET languages are expected to support.
Q8) Difference between Abstract Classes and Interfaces.
Following are the differences between Abstract Classes and Interfaces:
  1. When a derived class is inherited from an Abstract class, no other class can be extended then. Interface can be used in any scenario.
  2. Abstract class contains abstract method, i.e. actual implementation logic. On the other hand, interfaces have no implementation logic.
  3. Every method in an interface must be abstract. This is not necessary in case of abstract classes.
Q9) What is an Assembly?
In the .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .NET assemblies contain code in CIL, which is usually generated from a CLI language, and then compiled into machine language at runtime by the CLR just-in-time compiler.
An assembly can consist of one or more files. Code files are called modules. An assembly can contain more than one code module and since it is possible to use different languages to create code modules it is technically possible to use several different languages to create an assembly. Visual Studio however does not support using different languages in one assembly.
Q10) What are the various objects in Dataset?
The DataSet class exists in the System.Data namespace.
The Classes contained in the DataSet class are:
  1. DataTable
  2. DataColumn
  3. DataRow
  4. Constraint
  5. DataRelation
Q11) What is a NameSpace?
Namespace is a group of classes, structures, interfaces, enumerations, and delegates, organized in a logical hierarchy by function, that enable you to access the core functionality you need in your applications.
Namespaces are the way that .NET avoids name clashes between classes. A Namespace is no more than a grouping of data types, but it has the effect that the names of all data types within a namespace automatically get prefixed with the name of the namespace. It is also possible to nest namespaces within each other.
Q12) What is the difference between NameSpace and Assembly?
A Namespace is a logical naming scheme for types in which a simple type name, such as MyType, is preceded with a dot-separated hierarchical name. Such a naming scheme is completely under control of the developer. The .NET Framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as the ASP.NET application framework, or remoting functionality. Design tools can make use of namespaces to make it easier for developers to browse and reference types in their code.
The concept of a namespace is not related to that of an Assembly. A single assembly may contain types whose hierarchical names have different namespace roots, and a logical namespace root may span multiple assemblies. In the .NET Framework, a Namespace is a logical design-time naming convenience, whereas an Assembly establishes the name scope for types at run time.

Monday, April 8, 2019

What are the new features introduced in c# 4.0?

This is very commonly asked c# interview question. This question is basically asked to check, if you are passionate about catching up with latest technological advancements. The list below shows a few of the new features introduced in c# 4.0. If you are aware of any other new features, please submit those using the from at the end of this post.

1. Optional and Named Parameters
2. COM Interoperability Enhancements
3. Covariance and Contravariance
4. Dynamic Type Introduction

What's the difference between IEnumerable and List ?

1. IEnumerable is an interface, where as List is one specific implementation of IEnumerable. List is a class.

2. FOR-EACH loop is the only possible way to iterate through a collection of IEnumerable, where as List can be iterated using several ways. List can also be indexed by an int index, element can be added to and removed from and have items inserted at a particular index.

3. IEnumerable doesn't allow random access, where as List does allow random access using integral index.

4. In general from a performance standpoint, iterating thru IEnumerable is much faster than iterating thru a List

Difference between AS and IS in C# ?


The Difference between IS and As is that..
IS - Is Operator is used to Check the Compatibility of an Object with a given Type and it returns the result as a Boolean (True Or False).
AS - As Operator is used for Casting of Object to a given Type or a Class.
Ex. Student s = obj as Student;
is equivalent to:
Student s = obj is Student ? (Student)obj : (Student)null;
Both 'is' and 'as' keywords are used for type casting in C#.

IS Operator

Is Operator is used to Check the Compatibility of an Object with a given Type and it returns the result as a Boolean i.e. True Or False.

if(obj is string)
{
     ...
}
In the above code the keyword checks whether the value on its left side is an instance of the type on the right side.

AS Operator

As Operator is used for Casting of Object to a given Type or a Class. The as keyword is used to cast nullable types if the specified value is not an instance of the specified type.

MyClass myObject = obj as MyClass;

Difference between call by ref and call by out ?

1) Call by ref should be assigned before using where as Call by Out not required to assign a value.


Key Differences Between Ref and Out in C#

  1. When a variable preceded by the ref keyword is passed to any method then the changes made to it inside the method reflects in its original value. When a variable passed to a method is preceded by out keyword the method returns it without using return keyword.
  2. The ref parameter should be initialized before it is passed to a method. On the other hand, the out parameter must be initialized inside the method it is passed to.
  3. While calling, declaring, or defining a method, ref parameter is explicitly declared as ref. On the other hand, while calling, declaring, or defining a method, out parameter is explicitly declared as out.