Saturday, 21 December 2013

Interview Question on C#



Q :What is a C# ?

  • C# is a object oriented programming which is developed  by the Microsoft which is currently used on Application development in the .Net platform.
  •   It’s developed by Andres Hajasberg.
  • C# is an object oriented and user friendly. It gives security and reusability. We can develop multiple applications.
Q :What is the delegate ? 

 Delegate is a class which has the reference of a class or method. Delegate class has a signature and it can only reference those methods whose signature is compliant with the class. 
Delegates are type safe functions pointers or callbacks.
For more about  delegate click here

Q:What is the difference b/w convert.to.string and .to.string() method?
Convert function handles nulls while i.string() does not it will throw a null reference exception error.
Q:What is the difference between const and readonly?
  • Constants are dealt with at compile-time.
  • Constants support value-type variables so it is stored in stack .
  • Constants should be used when it is very unlikely that the value will ever change.

  • Read-only variables are evaluated at runtime.
  • Read-only variables can hold reference type variables so it is stored in heap.
  • Read-only variables should be used when run-time calculation is required.

Q:What are the type of comment in C# ?
    There are 3 types of comments in C# are :
  • Single line (//)
  • Multi (/* */)
  • Page/XML Comments (///).
Q:What is the difference b/w operator overloading and overriding ? 
operator overloading:-In which function name are same but the difference in only in passing perimeters. 
overriding:-In which all the function name and passing parameters are same. 

Q:What is the similarities  b/w structure and class?

  • Both can have constructors, methods, properties, fields, constants, enumeration, events and event handlers.
  • Structures and classes can implement interface.
  • Both can have delegates and events.
  • Both of them can have constructors with and without parameter.
Q:What are the wait handler? 
    Wait handles sends signals of a thread status from one thread to other thread. There are three types of wait modes are :
  • Wait One
  • Wait Any
  • Wait All
Q:What are the type of array ?
    There are three types of arrays in C# are :
  • Single-Dimensional arrays
  • Multidimensional arrays
  • Jagged arrays.
Q:What is the difference b/w System.String and System.StringBuilder classes?
  • System.String
  • 1.Its a class used to handle strings...
  • 2.Here concatenation is used to combine two strings...
  • 3.String object is used to concatenate two strings...
  • 4.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..
  • 5.we say "Strings are immutable". ..

  • String Builder....
  • 1.This is also the class used to handle strings...
  • 2.Here Append method is used...
  • 3.Here, Stringbuilder object is used...
  • 4.Insertion is done on the existing string...
  • 5.Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed
Q:What is the difference b/w boxing and unboxing ? 
When a value type is converted to the object type, the process is known as boxingand,alternatively, when an object type is converted to the value type, the process is known as unboxing.

Q:What is the difference b/w dataset.clone and dataset.copy ?
Dataset.clone copies just the structure of dataset (including all the datatables, schemas, relations and constraints.); however it doesn't copy the data.
Dataset.copy copies both the dataset structure and the data.
Q: what is the enum ?
It is used to define constants.
Q: How to prevent your class from being inherited by another class?
Yes. The keyword "sealed" will prevent the class from being inherited.
Q:Why is the virtual keyword used in code?
The Virtual keyword is used in code to define methods and the properties that can be overridden in derived classes.
Q:What is jagged array ?
A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array-of-arrays."











C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...