Search This Blog

Thursday 24 July 2014

All Dotnet Interview Questions 100-150

Question 101 - What is a Parameterized constructor?
Constructor that accepts arguments is known as parameterized constructor. There may be situations, where it is necessary to initialize various data members of different objects with different values when they are created. Parameterized constructors help in doing that task.

Question 102 - What is a Singleton Class?
·         A singleton class is such kind of class in which only one object is created throughout the life time of the class.
·         A Singleton class is used when you wish to restrict instantiation of a class to only one object.

Question 103 - What is a Partial Class?
·         It is possible to split the definition of a class or a struct, or an interface over two or more source files
·         Each source file contains a section of class definition, and all parts are combined at compile time.
·         All the partial definitions must proceeded with the key word "Partial".
·         All the partial types must be defined within a same assembly and module.
·         Method signatures (return type, name of the method, and parameters) must be unique
·         The partial types must have the same accessibility.
·         If any part is sealed, then the entire class is sealed.
·         If any part is abstract, the entire class is abstract.
·         Inheritance at any partial type applies to the entire class.

Question 104 - What is a Partial Method?
·         A partial method is like a usual method in a class except that the user may or may not implement it.
·         A partial method gets executed only when it has an implementation.
·         Definition of a partial method is in one part of the partial class and implementation in another, but it is legal to have both in the same part of the partial class. Also you can use a partial method in a partial structure but not in partial interface.
·         Partial methods are indicated by the partial modifier.
·         Partial methods must be private.
·         Partial methods must return void.
·         Partial methods must only be declared within partial classes.
·         Partial methods do not always have an implementation. 
·         Partial methods can be static and generic.
·         Partial methods can have arguments including ref but not out. 
·         You cannot make a delegate to a partial method.

Question 105 - What is a Delegate?
·         Delegate in C# is similar to a function pointer in C or C++.
·         Delegate is type which  holds the method(s) reference in an object. It is also referred as a type safe function pointers.
·         Delegate allows the programmer to encapsulate a reference to a method inside a delegate object.
·         The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.
·         An interesting and useful property of a delegate is that it does not know or care about the class of the object that it references.

Question 106 - What is a Syntax of Single class delegate?
·         Syntax - delegate result-type identifier ([parameters]);
§  result-type: The result type, which matches the return type of the function.
§  identifier: The delegate name.
§  parameters: The Parameters, that the function takes.

Question 107 - What are the advantages of Delegates?
·         Encapsulating the method's call from caller.
·         Effective use of Delegate improves the performance of application.
·         Used to call a method asynchronously.
·         A delegate type maintains three important pieces of information :
§  The name of the method on which it make calls.
§  Any argument (if any) of this method.
§  The return value (if any) of this method.

Question 108 - What is a Multicast Delegate?
·         Delegate wraps a method. Calling delegate results in calling the method. It is possible to wrap more than one method in a delegate. This is known as a multicast delegate.
·         If you make a call to a multicast delegate it will call all the functions it wraps in the order specified. Please note that functions in this case should not return any values.

Question 109 - What is an Event?
·         An event in C# is a way for a class to provide notifications to clients of that class when some interesting thing happens to an object.
·         An event is a way for a class to allow clients to give it delegates to methods that should be called when the event occurs. The most familiar use for events is in graphical user interfaces.
·         Event Handlers in the .NET Framework return void and take two parameters.
·         The first parameter is the source of the event; that is the publishing object.
·         The second parameter is an object derived from EventArgs.
·         Events are properties of the class publishing the event.
·         The keyword event controls how the event property is accessed by the subscribing classes.

Question 110 - What is a Hash Table?
·         Stored in two dimensional array and have a link format of Key and Value.
·         The Hashtable object contains items in key/value pairs. The keys are used as indexes.
·         The data type of Hashtable is object and the default size of a Hashtable is 16.
·         The keys are used as indexes. We can search value by using their corresponding key.
·         Items are added to the Hashtable with the Add() method.
·         A close friend of Hashtable is Array (came from C/C++), it is an instance of System.Array class.

Question 111 – What is the Constructor of Hashtable?
·         We have ten overloaded Constructor. we will see some important constructors of Hashtable.
·         Constructor with no parameters - Creates an empty Hashtable.
·         Constructor with an Integer Parameter - Creates an empty Hashtable.
·         Adding an element to the Hashtable  -- hashobject.Add(Key as Object, value as Object)
·         Accessing an element in the Hashtable -- hashobject.Item({key})
·         Deleting a Particular element -- hashobject.Remove(Key as object)

Question 112 – What is an Array?
·         Arrays are mechanisms that allow you to treat several items as a single collection.
·         All array types are implicitly derived from System.Array, which itself is derived from System.Object. This means that all arrays are always reference types which are allocated on the managed heap. There are 4 types of arrays as below.
§  Single Dimensional Array
§  Mutidimensional Array
§  Jagged Array
§  Mixed Array

Question 113 – What is a Single-dimensional arrays?
·         Single-dimensional arrays have a single dimension
·         Syntax - int[] i = new int[50];

Question 114 – What is a Multidimensional arrays?
·         A multidimensional array is an array with more than one dimension.
·         Multidimensional arrays are also called rectangular arrays because each row will be the same length.
·         Syntax : int[,] squareArray = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };

Question 115 – What are Jagged arrays?
·         One can create multidimensional arrays with irregular dimensions, using jagged arrays.
·         Jagged arrays are often called array of arrays. An element of a jagged array itself is an array.
·         For example, you can define an array of names of students of a class where a name itself can be an array of three strings - first name, middle name and last name. Another example of jagged arrays is an array of integers containing another array of integers.
·         Syntax : int[][] numArray = new int[][] { new int[] { 1, 3, 5 }, new int[] { 2, 4, 6, 8, 10 } };
Question 116 – What are Mixed Arrays?
Mixed arrays are a combination of multi-dimension arrays and jagged arrays.

Question 117 – What is an ArrayList?
·         An ArrayList is an array that can dynamically grow and shrink.
·         The arraylist is more dynamic, you can add and remove items without losing performance. With the ArrayList class, you can
§  add new items to a list
§  insert items inside a list
§  arrange items of a list
§  check the existence of an item in a list
§  remove an item from the list
§  inquire about the list
§  destroy the list.
·         using Sort on ArrayList or on Array is faster than most custom implementations. Because TrySZSort method used in the base class libraries is implemented in native code, it has been heavily optimized.
·         Example : ArrayList list = new ArrayList();

Question 118 – What is the difference between Array and Array List?
Array
ArrayList
Array is in the System namespace.
ArrayList is in the System.Collections namespace.
The capacity of an Array is fixed
ArrayList can increase and decrease size dynamically
An Array is a collection of similar items
ArrayList can hold item of different types
An Array can have multiple dimensions
ArrayList always has exactly one dimension
Char[] vowel=new Char[];
ArrayList a_list=new ArrayList();
Array is a primitive data structure, which stores thevalues in indexed format.
ArrayList is a more like a vector. (A re-sizeable array). It is a collection and stores any value as an object.

Question 119 – What is the Difference between Array and Collections?
·         Array are of fixed size, yes, it can be resized using Redim and Preserve. But for a Collection we can keep adding elements to it.
·         Arrays can store only one data type(Other than object array) whereas collections can hold any objects.
·         Accessing the element is very simple and very fast in collections.
·         Removing the element in Collection is very simple, in the case of arrays we need to shift the entire set of value up and reduce the size.

Question 120 – What is the difference between Array.Copy and Array.Clone?
Array.Copy:
·         Array.copy copies all data and structure.
·         performs a deep copy of the array.
·         CopyTo() copies the elements from the original array to the destination array starting at the specified destination array index.
·         The CopyTo() method copies the elements into another existing array.
Array.Clone
·         Array.clone copies only structure not data(ie only shadow part)
·         performs a shallow copy of the array.
·         Clone() method makes a clone of the original array.  It returns an exact length array.
·         The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.
Question 121 – What is a Shallow Copy?
A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.

Question 122 – What is a Deep Copy?
A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identical object. Basically it copies the source objects as well. So that there will be two different copies of the sources and objects.

Question 123 – What are the different String Compare options available?
String Functions
Description
String.Compare
Compares the values of two strings. Returns an integer value
String.CompareOrdinal
Compares two strings without regard to local culture. Returns an integer value
String.CompareTo
Compares the current string object to another string. Returns an integer value
String.StartsWith
Determines whether a string begins with the string passed. Returns a Boolean value
String.EndsWith
Determines whether a string ends with the string passed. Returns a Boolean value
String.Equals
Determines whether two strings are the same. Returns a Boolean value
String.ReferenceEquals
Returns true if both objects point to the same location in memory


Question 124 – What is a Statics Class
·         It is not possible to create instances of a static class using the new keyword.
·         A class can be declared static, indicating that it contains only static members.
·         If a class is declared as static then the variables and methods should compulsorily declared as static.
·         Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
·         Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

Question 125 – What are the advantages of using Static Class?
·         The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added.
·         The compiler will guarantee that instances of this class cannot be created.

Question 126 – List some of the main features of a Static Class?
The main features of a static class are:
·         They only contain static members.
·         They cannot be instantiated.
·         They are sealed.
·         They cannot contain Instance Constructors

Question 127 – What is a Static Member?
·         A static method, field, property, or event is callable on a class even when no instance of the class has been created.
·         Static members are often used to represent data or calculations that do not change in response to object state; for instance, a math library might contain static methods for calculating sine and cosine.
·         Static class members are declared using the STATIC keyword.
·         Static members are preloaded in the memory.

Question 128 – What is a Static Variable?
·         A static variable is a variable that will be the same in all instances of a class.
·         The initial value of a static variable is the default value of the variable's type.
·         A field declared with the static modifier is called a static variable. A static variable comes into existence before execution of the static constructor.
·         Normally each class as its own copy of all variables. If you declare some as static, then they will have the same value in each instance of a class.

Question 129 – What is a Static Method?
·         Static methods show have static keyword as the method definition
·         Static methods are accessed without creating an instance of the class object
·         Static methods will not have “this” functionality to access the method
·         Static methods cannot access non static members of the class.

Question 130 – What is a Nested Class?
·         A nested class is one that is created inside another class.
·         Nested classes have access to the private members of the outer class. So a scenario where this is the right way would be when creating a Comparer (ie. implementing the IComparer interface).
Nested classes are very useful for implementing internal details that should not be exposed. Question 131 – What is Shadowing or Hiding?
·         When global and local variable are in the same name, the local variable in a method which use to override the global is called the shadowing. ie the Global variable is being shadowed by local variable.
·         When two elements in a program have the same name, one of them can hide and shadow the other one. So in such cases the element which shadowed the main element is referenced.
·         This is a VB.Net Concept by which you can provide a new implementation for the base class member without overriding the member.
Hiding is the C# concept equivalent for shadowing.
·         You can shadow a base class member in the derived class by using the keyword Shadows.
·         Shadowing is bad programming practice according to OOPs concepts.
·         In shadowing signature could be different.
·         In Shadowing both Derived class and Base Class methods are available for use.(So it’s a bad practice)
·         The access level signature and the return type can only be changed when you are shadowing with VB.NET. Hiding and overriding demands the these parameters as same in C#.

Question 132 – What are Out and Ref parameters?
·         The out parameter -  return the values in the same variable passed as a parameter of the method. Any changes made to the parameter will be reflected in the variable.
·         The ref keyword on a method parameter causes a method to refer to the same variable that was passed as an input parameter for the same method. If you do any changes to the variable, they will be reflected in the variable.
·         The implementation of ref and out parameter in IL Code(in CLR) is same, there is no difference whether you use ref or out parameters.

Question 133 – What are the differences of Out and Ref Parameters?
REF
OUT
Ref must be initialized before it is passed to the method
Out its is not necessary, but after method call it should get initialized
Extra performance cost.
Faster
The called method can read the argument at anytime
The called method must initialize the parameterbefore reading it
ref parameters are used to get a value and return a change to that value(Secondary value)
out parameters are used when you just need to geta secondary return value

Question 134 – What are the differences between String and String Builder?
String
String Builder
String objects are immutable, which means that once they are created they cannot be changed. When we use one of the methods of the String class, we create a new string object.
StringBuilder are mutable class, which means whenconcatenate any text to the variable it allows us to modify the original value without creating a new object.
Here concatenation is used to combine two strings.
Here Append method is used.
String object is used to concatenate two strings.
Stringbuilder object is used.
The first string is combined to the other string by creating a new copy in the memory as a string object, and then the old string is deleted
Insertion is done on the existing string.
Less efficient
StringBuilder is more efficient for large amounts of string manipulations

Question 135 – Why C# is strongly typed language?
C# is called Strongly Typed Language because its type rules are very strict. For example you can't called a function that is designed to call Integer with a string or decimal. If you want to do so then you will have to explicitly convert them to integer.
 Question 136 – What are Imperative and Interrogative function?
·         Imperative methods return values or provide information back to the calling code. It returns a value.
·         Interrogative methods, just perform a service and return nothing to the calling code. It does not return a value.

Question 137 – What is a Collection Class?
·         A collection is a set of the same type of objects that are grouped together and that is able to supply a reference to an enumerator. Part of the System.Collections or System.Collections.Generic namespace
·         An enumerator is an object that iterates through its associated collection. It can be thought of as a movable pointer pointing to any element in the collection. In order to provide an enumerator, a class must implement the IEnumerable interface.
·         Most collection classes derive from the interfaces ICollection, IComparer, IEnumerable, IList, IDictionary, and DictionaryEnumerator and their generic equivalents.
·         Using generic collection classes provides increased type-safety and in some cases can provide better performance, especially when storing value types.

Question 138 – What are the differences between Const & Readonly?
Const
Read Only
Must be initialized at the time of its creation
Assigned in constructor and called at Runtime
Used if we want to define something at compile time.
At Runtime you can make use of the value
Protects from accidentally changing value of the field

Can't be static.
Can be either instance-level or static.
Value is evaluated at compile time.
Value is evaluated at run time.
Initialized at declaration only.
Initialized in declaration or by code in the constructor


Question 139 – What is a Stack?
·         Stack is responsible of keeping track of running memory needed in your application.
·         As the name says stack it stacks this memory allocation on the top of the first memory allocation. You can think about stack as series of compartment or boxes put on top of each other.
·         Memory allocation and de-allocation is done using LIFO (Last in first out) logic. In other words memory is allocated and de-allocated at only one end of the memory i.e. top of the stack.
·         Reference pointers are allocated on stack.
·         At the end event clears all the memory variables which are assigned on stack
·         Static Memory – Stack
·         Details stored in stack are Name, Data type and Value of the variable.

Question 140 – What is a Heap?
o    It creates a pointer on the stack and the actual object is stored in a different type of memory location called as ‘Heap’. ‘
o    Heap’ does not track running memory it’s just pile of objects which can reached at any moment of time.
o    Heap is used for dynamic memory allocation. FIFO (‘First In First Out’)
o    Instance created using new keyword it will be in HEAP.
o    It did not de-allocate the heap memory. This memory will be later de-allocated by “Garbage Collector”.
o    Dynamic Memory – Heap
Question 141 – What are Value Types?
·         Value types are types which hold both data and the memory on the same location.
·         When we assign the ‘int’ value to the other ‘int’ value it creates a complete different copy. These kinds of data types are called as ‘Value types’.
·         Value Types in .Net are
§  Double, Float, Integer types (sByte, byte, short, ushort, int, uint, long, ulong, char)
§  Decimal, Bool, Enumeration types

Question 142 – What are Reference Types?
·         Reference type has a pointer which points to the memory location.
·         When we create an object and when we assign one object to the other object, they both point to the same memory location. In other words if we change one of them the other object is also affected this is termed as ‘Reference types’.
·         Reference Types in .Net
§  String and Object

Question 143 – What are Boxing and UnBoxing means?
·         Move a value type to reference type -- stack to the heap – BOXING
·         Move reference type to a value type -- heap to the stack -- UNBOXING

Question 144 – What is Early Binding?
·         Early binding is nothing but declaring the Object of specific type. With this kind of object its cant be used to hold any other type of the Object/class.
·         Early bound just means the target method is found at compile time.
·         If the method doesn't exist the compiler will fail to compile the code.
·         Most script languages use late binding, and compiled languages use early binding.
·         The compiler guarantees that the function takes the right number of arguments, correct type and return value is of the correct type.

Question 145 – What is Late Binding?
·         Declaring an object of generic type and that object be used to hold the instance of the any object/Class.
·         Late bound means the target method is looked up at run time.
·         If the method isn't there, then program will crash or go to some exception handling scheme at run time.
·         Most script languages use late binding, and compiled languages use early binding.
·         The target function may not accept the arguments passed to it, and may have a return value of the wrong type.

Question 146 – What are the different WCF binding available?
·         BasicHttpBinding    Basic Web service communication. No security by default
·         WSHttpBinding    Web services with WS-* support. Supports transactions
·         WSDualHttpBinding    Web services with duplex contract and transaction support
·         WSFederationHttpBinding    Web services with federated security. Supports transactions
·         MsmqIntegrationBinding    Communication directly with MSMQ applications. Supports transactions
·         NetMsmqBinding    Communication between WCF apps by using queuing. Supports transactions
·         NetNamedPipeBinding    Communication between WCF apps on same computer. Supports duplex contracts and transactions
·         NetPeerTcpBinding    Communication between computers across peer-to-peer services. Supports duplex contracts
·         NetTcpBinding    Communication between WCF apps across computers. Supports duplex contracts and transactions

Question 147 – What is a BasicHttpBinding?
This binding is used when we need to use SOAP over HTTP.

Question 148 – What is a WSHttpBinding?
It is same like BasicHttpBinding. In short, it uses SOAP over HTTP. But with it also supports reliable message transfer, security and transaction.
Question 149 – What is a NetTcpBinding?
This binding sends binary-encoded SOAP, including support for reliable message transfer, security, and transactions, directly over TCP. The biggest disadvantage of NetTcpBinding is that both server and client should be also made in .NET language.

Question 150 – What is a WSDualHttpBinding?
·         The WSDualHttpBinding class is used to provide a secure and interoperable binding.
·         It is used with duplex service contracts to let both services and clients send/receive messages.
·         It assists Web Service protocols as does the WSHttpBinding class but for duplex contracts.
·         The WSDualHttpBinding class only supports SOAP security and requires reliable messaging.
§  Advantage: can get immediate response w/o waiting on polling timer
§  Disadvantage: less scalable than WsHttpBinding
§  Disadvantage: less firewall friendly

§  Disadvantage: slower than WSHttpBinding

No comments:

Post a Comment