Ads 468x60px

For New Update Use this Link Offer for you


Friday, 28 June 2013

boxing and unboxing in c#

boxing and unboxing in c#
Boxing :-

  means converting value-type to reference-type.


int I = 20;

string s = I.ToSting();

UnBoxing :- 
 means converting reference-type to value-type.


int I = 20;

string s = I.ToString(); //Box the int

int J = Convert.ToInt32(s); //UnBox it back to an int.

Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.

Value Type :-
As name suggest Value Type stores “value” directly.
For eg: 

//I and J are both of type int
I = 20;
J = I;

int is a value type, which means that the above statements will results in two locations in memory.
For each instance of value type separate memory is allocated.Stored in a Stack.
It Provides Quick Access, because of value located on stack.
 Reference Type : -

As name suggest Reference Type stores “reference” to the value.
For eg: 

Vector X, Y; //Object is defined. (No memory is allocated.)
X = new Vector(); //Memory is allocated to Object. //(new is responsible for allocating memory.)
X.value = 40; //Initialising value field in a vector class.
Y = X; //Both X and Y points to same memory location. //No memory is created for Y.
Console.writeline(Y.value); //displays 40, as both points to same memory
Y.value = 60;
Console.writeline(X.value); //displays 60.
Note: If a variable is reference it is possible to indicate that it does not refer to any object by setting its value to null;

Reference type are stored on Heap.
It provides comparatively slower access, as value located on heap.

Thursday, 20 June 2013

ADO.Net Interview Questions and Answers

Late binding and Early binding in c#
 Categories : - Late Binding and Early Binding in C#.Net , Latest Inter View Question and Answer

Define  ADO.NET ?

The full form of ADO is ActiveX Data Object.

ADO.NET is one of the component in the Microsoft.NET framework which contains following features to Windows, web and distributed applications.
1. Data Access to the applications from Database in connected (Data reader object) and disconnected (Data set and data table) model.
2. Modify the data in database from application.

What is the namespace in which .NET has the data functionality class? 

namespaces provided by .NET for data management:

 1. System.Data
This contains the basic objects used for accessing and storing relational data, such as DataSet, DataTable, and DataRelation. Each of these is independent of the type of data source and the way we connect to it.

2 .System.Data.OleDB 

It contains the objects that we use to connect to a data source via an OLE-DB provider, such as OleDbConnection, OleDbCommand, etc. These objects inherit from the common base classes, and so have the same properties, methods, and events as the SqlClient equivalents.
3 .System.Data.SqlClient
his contains the objects that we use to connect to a data source via the Tabular Data Stream (TDS) interface of Microsoft SQL Server (only). This can generally provide better performance as it removes some of the intermediate layers required by an OLE-DB connection.

4 .System.XML
This contains the basic objects required to create, read, store, write, and manipulate XML documents according to W3C recommendations.

What are the Benefits of ADO.Net?


 XML Format is one of the best formats for Interoperability.ADO.NET supports to transmit the data using XML format.


 ADO.NET works on Dataset that can represent a whole database or even a data table as a disconnected object and thereby eliminates the problem of the constraints of number of databases being connected. In this way scalability is achieved.

The performance in ADO.NET is higher in comparison to ADO that uses COM marshalling.


ADO.Net Data components in Visual studio help to do easy program to connect to the database.

What are the two fundamental objects in ADO.NET?

DataReader and DataSet are the two fundamental objects in ADO.NET.

What are the major difference between classic ADO and ADO.NET?

Some major differences: 

1 : - In ADO, we have a Recordset and in ADO.NET we have a DataSet.

2 : -In Recordset, we can only have one table. If we want to accommodate more than one table, we need to  do inner join and fill the Recordset. A DataSet can have multiple tables.

3 : -All data is persisted in XML as compared to classic ADO where data is persisted in binary format.

What is the use of a data adapter?

These objects connect one or more Command objects to a DataSet object. They provide logic that would get data from the data store and populates the tables in the DataSet, or pushes the changes in the DataSet back into the data store.

1 : - An OleDbDataAdapter object is used with an OLE-DB provider
 2 : - A SqlDataAdapter object uses Tabular Data Services with MS SQL Server.

What are the different steps to access a database through ADO.NET?

The DataSet provides the basis for disconnected storage and manipulation of relational data. We fill it from a data store, work with it while disconnected from that data store, then reconnect and flush changes back to the data store if required.

C#.Net Interview Question and Answer For Freshness and Experience

Tuesday, 18 June 2013

Late binding and Early binding in c#

Late binding and Early binding in c#
This is very common  question for interview so read carefully before attend the interview.It's related to OOPS concepts .

Early Binding :-

1 - In C#, early binding is a process in which a variable is assigned to a specific type of object during its declaration to create an early-bound object.

2- Early binding is also known as compile time polymorphism, static binding and static typing.

3 - During early binding, the C# compiler performs syntax and type checks to ensure that the correct parameter amount and type are passed to the method or property. 

4 - Non-virtual methods are always early bound  

5 -  Early bound just means the target method is found at compile time, and code is created that will call this. Whether its virtual or not (meaning there's an extra step to find it at call time is irrelevant). If the method doesn't exist the compiler will fail to compile the code.

6 - Example

string s = "Hello word";
s.Trim();  // Early bound call to the Trim() method

Late Binding - 

1 - Late bound means the target method is looked up at run time. Often the textual name of the method is used to look it up. If the method isn't there, bang. The program will crash or go into some exception handling scheme at run time.

2 -  Late binding is also known as Run  time polymorphism, Dynamic binding .

3 - Calling methods using reflection is an example of late binding. We write the code to achieve this as opposed to the compiler. (E.g. calling COM components.)

4 - Virtual methods are always late bound

5 - By using late binding in C# you cannot determine the error at compile time because compile time does not have any information about assembly type

6 - Example

Object Objitems;

Objitems=CreateObject("Dll Or Assembly Name");
Early Binding  VS Late Binding

  • Application will run faster in Early binding, since no boxing or unboxing are done here.  
  • Easier to write the code in Early binding, since the intellisense will be automatically populated 
  • Minimal Errors in Early binding, since the syntax is checked during the compile time itself. 
  • Late binding would support in all kind of versions, since everything is decided at the run time. 
  • Minimal Impact of code in future enhancements, if Late Binding is used. 
  • Performance will be code in early binding.

  • Monday, 17 June 2013

    What is index in sql server

    what is index in sql server

    Indexes: -
    Indexes in SQL Server are similar to the indexes in books. They help SQL Server retrieve the data quicker.

    Type of Indexs :-
    Indexes are of two types.  1-:   Clustered indexes   2-: non-clustered indexes

    Clustered indexes :- 

    you create a clustered index on a table, all the rows in the table are stored in the order of the clustered index key. So, there can be only one clustered index per table.

    Non-clustered indexes :-

    Non-clustered indexes have their own storage separate from the table data storage. Non-clustered indexes are stored as B-tree structures (so do clustered indexes), with the leaf level nodes having the index key and it’s row locater. The row located could be the RID or the Clustered index key, depending up on the absence or presence of clustered index on the table.

    Advantages of Indexes :-
    1-:  If you create an index on each column of a table, it improves the query performance, as the query optimizer can choose from all the existing indexes to come up with an efficient execution plan.

    Disadvangages of Indexes :-
    1 -: At the same t ime, data modification operations (such as INSERT, UPDATE, DELETE) will become slow, as every time data changes in the table, all the indexes need to be updated.

    2-: Another disadvantage is that, indexes need disk space, the more indexes you have, more disk space is used.

    Friday, 14 June 2013

    crete and read xml file in

    crete and read xml file in
    Introduction :-

    In this article i am explain how i can create a xml file dynamically in  .

    Description :-

    In my previous article i have explained how i can read the XML file in i will explain how i can write data in XML file and read from the XML file which data i have inserted .

    Note :- You have no need to create a xml file manually at the running time automatically create the XML file .

     Aspx Design code as shown below

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="read_write_xmlfile.aspx.cs" Inherits="read_write_xmlfile" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns="">
    <head runat="server">
        <title>Read and write into xml file</title>

        <style type="text/css">
                text-align: left;
                color: #FFFFFF;
        <form id="form1" runat="server">
        <b style="text-align: left"><span class="style2">Read Write XML File in Asp.Net<br />
            <br />
            <br />
            </span></b><br /></div>
        <table width="50%"><tr><td width="50%" valign="top">
    <b>Employee Details:</b><br /><br />

    <td><asp:Textbox id="txtName" runat="server"/></td></tr>

    <tr><td>Department: </td>
    <td><asp:Textbox id="txtDept" runat="server"/></td></tr>

    <tr><td>Location: </td>
    <td><asp:Textbox id="txtLocation" runat="server"/></td></tr>

    <tr><td colspan="2" align="right">
    <asp:Button ID="btnWriteXml" runat="server" Text="Write XML File"
            onclick="btnWriteXml_Click" style="height: 26px"/>

    <td width="50%" valign="top">Read XML File :
    <asp:Button id="btnReadXml" text="Read XML File" runat="server"
    <asp:label id="lblXml" runat="server"/></td></tr>


     Include the name space in code behind file for xml read and writer and Encoding.UTF8
    as shown below

    using System.Xml; //for xml
    using System.Text; //Encoding.UTF8

    Code behind  file code as shown below

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml; //for xml
    using System.Text; //Encoding.UTF8

    public partial class read_write_xmlfile : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)

        protected void btnWriteXml_Click(object sender, EventArgs e)
            XmlTextWriter xmlWriter = new XmlTextWriter(Server.MapPath("EmployeeDetails.xml"), Encoding.UTF8);
            //Create Parent element
            //Create Child elements
            xmlWriter.WriteElementString("Name", txtName.Text);
            xmlWriter.WriteElementString("Department", txtDept.Text);
            xmlWriter.WriteElementString("Location", txtLocation.Text);

            //End writing top element and XML document
            txtDept.Text = "";
            txtLocation.Text = "";
            txtName.Text = "";

        protected void btnReadXml_Click(object sender, EventArgs e)
        protected void ReadXmlFile(string xmlFile)
            string parentElementName = "";
            string childElementName = "";
            string childElementValue = "";
            bool element = false;
            lblXml.Text = "";

            XmlTextReader xmlReader = new XmlTextReader(xmlFile);
            while (xmlReader.Read())
                if (xmlReader.NodeType == XmlNodeType.Element)
                    if (element)
                        parentElementName = parentElementName + childElementName + "<br/>";
                    element = true;
                    childElementName = xmlReader.Name;
                else if (xmlReader.NodeType == XmlNodeType.Text | xmlReader.NodeType == XmlNodeType.CDATA)
                    element = false;
                    childElementValue = xmlReader.Value;
                    lblXml.Text = lblXml.Text + "<b>" + parentElementName + "<br/>" + childElementName + "</b><br/>" + childElementValue;
                    parentElementName = "";
                    childElementName = "";

     Output as shown below

    After Insert the Record into the textbox and press the button Write XML File  And Click on Read XML File  as shown below

    Download sample code attached

    read data from xml file in

    read data from xml file in
    Categories:-aspdotnet interview question and answer , create wcf restful web service in

    Introduction :-  

    Here i am explain how i can retrieve  data from XML  file in show the data of XML file on the web form.

    Description :-

    XML stands for Extensible Markup Language.XML is a markup language much like HTML. Using xml we can store the data and we can easily retrieve and display the data without using database in our application.Using XML no need to connect any database. If  we  want to display data dynamically then we use the XML file.On the XML file we can Perform the read write and update  operation .
    Now  i will explain how i can read data from xml in

     Design your aspx page as show below

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="xmlpageread.aspx.cs" Inherits="xml_file_xmlpageread" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns="">
    <head runat="server">
        <style type="text/css">
            .style1 {
                text-align: center;
        <form id="form1" runat="server">
        <div class="style1">
            Enter ID
            <asp:TextBox ID="txt_id" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
            <br />
            <br />
            <br />

    In the above aspx page design i have taken a one textobx and on button .Textbox use for insert the Employee id  which present in xml file and press submit button get the detail related to this employee id.

    code behind file as show below

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Xml;

    public partial class xml_file_xmlpageread : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        protected void Button1_Click(object sender, EventArgs e)

                string empid1 = txt_id.Text.ToString();
                if (empid1 != null)
                    //Response.Write("<br>XML file searching using<br><br>");
                    XmlDocument doc = new XmlDocument();

                    string xmlFile = System.Web.HttpContext.Current.Server.MapPath("~/XMLFile.xml");
                    int empid = int.Parse(empid1);// convert the empid1 to int

                    XmlNodeList xmlnode = doc.GetElementsByTagName("blockid"); //this is tag of xml file
                    for (int i = 0; i < xmlnode.Count; i++)

                        XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
                        if (int.Parse(xmlattrc[0].Value) == empid)
                            Response.Write("<br>Employee-ID: " + xmlattrc[0].Value);
                            Response.Write("<br>First Name: " + xmlnode[i].ChildNodes[0].InnerText);     
            catch (Exception exp)

    Xml Form at run time as show below

    Enter the Employee Id Into the textbox and press submit button the display the output as shown below
    Download sample code attached

    Thursday, 6 June 2013

    how to set start page in

    how to set start page in
    Introduction :- 
    In this article i will explain how i can set the start up page that means default page of our website when we run.When we Run our website the we always set the index page as a starting page but some time our index page not run when we start the website our other page is run.

    Description :- 
    First a fall create a website like this .Open visual stdio->file->new->website
    and select web site and rename the name of site page and click OK
    Image of project creation as shown below

    write click on project and add  new item and select as   web form and rename the page like index.aspx

    Different way to show the start up page in

     way [1]->
    write click on project explorer and  property page and start up project->specific page and write the name[index.aspx ]and click ok.Image as shown below

    Run our application and your application always start from index.aspx page.

    Way [2]->

    write Click on page which you want to set as startup page. And  set as a start page->ok
    Your starup page create successlly. Image as shown below

    your start up page create successfully

    way [3]->

    Minear change in web.config file and set index .aspx as default page
    Write the code in web.config file as shown below

            <add value="default.aspx"/>

     <if you want to set any page as a start up page then change in <add values="your page  name">
    and save and compile web.config file



    New Updates

    Related Posts Plugin for WordPress, Blogger...

    Related Result