Wednesday 19 August 2015

What is Exception Handling in .Net

        It is a process of stopping the abnormal termination of a program whenever an exception occur and execute the code that  is not related with exception.

Handling an Exception  : 
                If we want to handle an exception code has to enclosed under some special blocks known as try, catch blocks. Which has to used as following

Syntax :
                 try
                    {
                           --statements which will cause an exception
                           -- statements which should not be executed when an exception occurs.
                    }
               catch(<exception> <var>)
                 {
                           -- Statements which should be executed only when an exceptions occurs
                 }
           --- < Multiple catch blocks of required >--
           

Anonymous types in C#.net

        Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. You can create anonymous types by using the new operator together with an object initializer .

Example :  var value = new { salary=1000 , message = "Hi"};

        Anonymous types typically are used in the select clause of a query expression to return a subset of the properties from each in the source sequence.

 Example :
var salary = from sal in db.Employee where sal.empid ==1 select new {sal.salary,sal.Message}

Asp.Net Page life Cycle

      Set of sub-programs executed towards each time of web page processing are called asp.net page life cycle.

Events :

Page pre-init : This will be executed before memory initialization for webpage.

          Eg : Attaching theme, maser page dynamically to webpage is possible using pre-init event procedure.

Page Init :  This will be executed when memory is initialized for web page.

Page Load :  This will be executed when submitted data and controls are loaded.
       Eg : DataBase connectivity, Reading submitted data can be placed within  page load.

Page PreRender : This will be executed before rendering  HTML content for server side control.

Page unload :  This will be executed once memory is released for web page.

   Eg : Database connection closing

What is difference between Cookie and Session in Asp.Net

The differences between Cookie and Session.

Cookie : 

       1. Cookie is client side state management.

       2. Cookie support only plain text representation.

       3. Cookie is having limitations in terms of number and size.

       4. Cookie doesn't provide security.

       5.  Cookies will reduce burden on server compare to session.

       6. No time out for cookie


 Session : 

       1. Session is server side state management.

       2. Session support representing object.

       3. Session doesn't have limitations for number and size.

       4. Session provides security.

       5.Session time out is 20 mins

     

What is Cookie in asp.net

   Cookie is a small amount of memory used by web server within client system.

The purpose is maintaining personal information of client within client system to reduce on server.

Cookie can be classified into 2 types

                       1. In-memory cookie

                       2. Persistant cookie

1. In-Memory Cookie :   The Cookie placed within browse process memory is called in-memory cookie.


  •    It is temporary cookie specific to browser instance. Once browser will be closed, cookie will be erased.
  • Cookie data will be accessible to all the web pages with client request.
  • .Net is providing HttpCookie class for sending cookie or reading cookie.
     Sending Cookie : 

                   HttpCookie obj = new HttpCookie("Name");

                                       obj.value = "100";

                  Response. Appendcookie(obj);

        
     Reading Cookie submitted by client : 

                      HttpCookie obj = null;

                                       obj = Request.Cookie["Name"];

                            if ( obj == null)

                            {
                              // No cookie submitted       
                            }
                            else
                                obj.value ;


2.  Persistant Cookie : 
                                      Cookie placed with in hard disk memory of client system is called persistant cookie. This will be maintained by client system with perticular lifetime.
                             



What is difference between Array and ArrayList in C#.net

Array :


  •  Char[] vowel = new char[];
  • Array is in the System Namespace.
  • The capacity of an array is fixed.
  • Array is a collection of similar items.
  • An Array can have multiple dimensions.
ArrayList : 

  •  ArrayList alist = new ArrayList();
  • ArrayList is in the system.Collections namepace.
  • ArrayList can increase and decrease size dynamically.
  • Arraylist is a collection of dis-similar items.
  • ArrayList always has exactly one dimentions.


What is difference between the Delete and Truncate in Sql server

Delete :
  • Delete can delete all rows or particular rows .
  • Delete is the DML Command. (DML Stands for Data manipulation language)
  • Delete is recorded in log file.
  • Data can be restored.
  • Delete will not reset Identity.
   Syntax: delete from <tablename> [where <cond>]


    examples: 
  •   delete * from emp . (delete all the rows from emp table)
  •   delete * from emp where job in ('clerk','manager')  (Delete the employee record working as      clerk or manager).  
Truncate :
  •  Truncate command is used to release memory allocated for the table.
  •  Truncate can delete  only all rows.
  •  Truncate is not recorded in log file.
  • Data can't be restored.
  • Truncate will reset Identity.
  • truncate is faster than delete
Syntax: 
  •      truncate table<tablename>.
Example :
  •   Truncate table emp