Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

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."











IsPostBack


Q:How can we Identify that the page is Post Back :-

Page object has an "Ispostback" property, which can be checked to know that is the page posted back.

Q:What is a Post Back:-
The Process in which a web page sends Data Back to the same page on the server.

View State IN Dot Net

View State in Dot Net:

Introduction:- It is used to maintain the state of controls during Page post back and if we save any control value or anything in view state we can access those value through out the page whenever it require for that check.

View state information stored in Html Hidden Field.

Q : How do you enable or disable a ViewState for a control on the page?
Ans : Every ASP.NET control has a property called EnableViewState. If EnableViewState is set to true ViewState is enabled for the control. If EnableViewState is set to false ViewState is disabled for the control.
Q : How do you enable or disable a ViewState at the page level?
Ans : At the page level you can enable or disable ViewState using EnableViewState property of the page.
Q : What is the name of the hidden form field in which ViewState of the page is saved?
Ans : _ViewState
Q : What are the performance implications of ViewState?
Ans : ViewState is usually good to retain the state of the controls on the webform across postbacks. If you have a huge DataGrid with tons of data being loaded on every page load. It is a good idea to disable the ViewState of the DataGrid for the page to load faster. If the ViewState of a large DataGrid is not disabled, ViewState can easily get very large, on the order of tens of kilobytes. Not only does the __ViewState form field cause slower downloads, but, whenever the user posts back the Web page, the contents of this hidden form field must be posted back in the HTTP request, thereby lengthening the request time, as well.
Q : When does ViewState restoration happens?
Ans : During the Page_Init event
Q : What are the disadvantages of using ViewState?
Ans : 1. On all page visits, during the save view state stage the Page class gathers the collective view state for all of the controls in its control hierarchy and serializes the state to a base-64 encoded string. (This is the string that is emitted in the hidden __ViewState form filed.) Similarly, on postbacks, the load view state stage needs to deserialize the persisted view state data, and update the pertinent controls in the control hierarchy.

2. The __ViewState hidden form field adds extra size to the Web page that the client must download. For some view state-heavy pages, this can be tens of kilobytes of data, which can require several extra seconds (or minutes!) for modem users to download. Also, when posting back, the __ViewState form field must be sent back to the Web server in the HTTP POST headers, thereby increasing the postback request time.
Q : Is ViewState encoded?
Ans :Yes, ViewState is base-64 encoded.
Q : What happens during the Page_Init event?
Ans : The server controls are loaded and initialized from the Web form’s view state. This is the first step in a Web form’s life cycle.

Coding For View State

protected void page_load(object sender,Event args e)

{

if (! ispostback)

{

string str = "welcome to Asp.net-munesh blog";

if(view state["sample text"]==NULL )

{

view state["sample text"]==str;

}}}

protected void btnclick_click (object sender,Event args e)

{

lblstring.text = viewstate["sample text"].to string();

} 



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...