Showing posts with label caching. Show all posts
Showing posts with label caching. Show all posts

Wednesday 19 April 2017

Technical Interview Question Answer

Generics:

1. Generics separate the logic from the datatype,in this way we increase reusability .
2. Parameterized type is called template in c++ and generics in c#.
3. It is mainly used for create  collection classes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace test
{
    public class Generic_Example<UNKNOWNDATATYPE>
    {

        public bool Compare(<UNKNOWNDATATYPE x, UNKNOWNDATATYPE y)
        {
            if(x.Equals(y))
            {
                return y;
            }
            else
            {
                return x;
            }
        }
    }

    static void Main(string[] args)
    {
        Generic_Example<int> obj = new Generic_Example<int>();
        bool b1 = obj.Compare(1, 1);

        Generic_Example<string> objstring = new Generic_Example<string>();
        bool b2 = objstring.Compare("Sandeep", "Pranali");
    }
}




Difference Between string and String :

string  & String 
1. It is a data type in c#.
2. System.String is a type in the CLR.
When you use C# together with the CLR string  will be mapped to System.String.
Example : String s="I ma String";
                  string s="I am string";
3. string is a keyword and you can not  use it as an identifier.
4. String is not a keyword and you can use it as an identifier.
    string is for variables
5. String is for calling other String class methods .
    
          string fName = "Sandeep";
           string lName = "Jamkar";
        string fullName = String.Concat(fName, lName);
        if(String.IsNullOrEmpty(fName))
        {
            Console.WriteLine("Enter First Name");

        }

Var key word in C#. :

1. var key word is an implicit way of defining data type.
2. In simple words var key word looks like the data right hand side or accordingly 
creates data type of the left hand.

    int i=0;==>Explicit[Direct]
you are directly defining the datatype.

var i=0;==>Implicit[Indirect]
By looking right hand side the left hand data type is created.

3. var keyword define data type statically or not on runtime. 

Uses:
Long class names makes code readable 
Linq and anonymous type

Wednesday 31 July 2013

Components of ADO.Net ,execute scalar and execute non query,difference asp .net web forms and asp .net mvc.



Component of ADO .Net  :

following are the important component of ADO .net


1.  Data Set

2.  Data Reader
3.  Data Adaptor
4.  Command
5.  Connection

DataSet :


1 . It is disconnected orient architecture that means there is no need of active connections during              work with dataset.
2 . It is a collection of data tables and relations between tables.
3 . It is used to hold multiple tables with data.
4 . It provides you with rich features like saving data as XML .


// Following method is used to bind gridview from database with connection.

protected​ void​ BindMyGridview()

{


SqlConnection​ connection  = newSqlConnection("Data Source=MyUsers;Integrated Security=true;Initial Catalog=MySampleDataBase") 
connection.Open();


SqlCommand​ command = new​ SqlCommand("select Fname,Lname,Jlocation from UserData",connection);


SqlDataAdapter​ dap =new SqlDataAdapter(command);

DataSet​ dst = new​ DataSet();


dap.Fill(dst); 

gvUserData.DataSource = dst; 

gvUserData.DataBind();


}

Data Reader :


1. It is used to read the data from database.
2. It is a read and forward only connection oriented architecture.
3. It fetch the data from database. 
4. It is used to iterate through result set that came from server.
5. It will read one record at a time.
6. It will fetch the data very fast when compared with dataset. 

// Following method is used to bind gridview from database with connection.

protected​ void​ BindMyGridview()

{


SqlConnection​ connection  = newSqlConnection("Data Source=MyUsers;Integrated Security=true;Initial Catalog=MySampleDataBase") 
{

connection.Open();

SqlCommand​ command = new​ SqlCommand("select Fname,Lname,Jlocation from UserData",connection);


SqlDataReader​ dr = cmd.ExecuteReader();

gvUserData.DataSource = dr; 

gvUserData.DataBind();

con.Close();
}
}

Data Adaptor :

1. It will acts as a Bridge between DataSet and database. 
2. Dataadapter object is used to read the data from database and bind that data to dataset. 
3. It is a disconnected oriented architecture. 

// Following method is used to bind gridview from database with connection.

protected​ void​ BindMyGridview()

{


SqlConnection​ connection  = newSqlConnection("Data Source=MyUsers;Integrated Security=true;Initial Catalog=MySampleDataBase") 
{

connection.Open();

SqlCommand​ command = new​ SqlCommand("select Fname,Lname,Jlocation from UserData",connection);

SqlDataAdapter dap = newSqlDataAdapter(command); 

DataSet​ dst = newDataSet();


dap.Fill(dst);

gvUserData.DataSource = dr; 

gvUserData.DataBind();


}

}