Tuesday, June 23, 2015

Interview Questions C#

C# 

1. Array List and Hash Table
  • Data is stored in name value pair in hash table, where as in has in array list only value is stored.
  • To access hash  table only you need name,  where as to access array list index is required.
  • You can store different type of data in hash table, while only similar type of data is stoed in array list.
2. String builder and system.string
  • system.string in immutable where as string builder is mutable
  • append key word is used to add data in string builder but not in system.string
3. Application and Session object
  • Session object is used to maintain the session of each user. If a user enters an application,  a session id is created and when he leaves the id is deleted.
  • Application object is used to maintain the id for whole application
4. Interface and Abstract Class
  • Abstract class cannot be instantiated, but inherited where as interface can be.
  • Abstract class contains class definitions and declaration, where as interface contains only declarations.
  • A class which contains only abstract method is an interface class, where as a class which abstract method is an abstract class.
  • Only public access specifier can be used in Interface, but abstract can have any access specifier

5. Boxing and Unboxing
  • Boxing: Converting value type into reference type
  • Unboxing: Converting reference type into value type
6. Level of state management

7. How to pass optional parameter in method.
 There are two ways


  • If you use C# version 4.0,then Optional parameter can be used by Assignment statement
  • public void SendCommand(String command, string strfilename=null)
  • By Using Param Keyword
8. Difference between out and Ref
  • Out requires variable value to be SET before leaving the method.
  • While ref does NOT require variable to set
9. What is a chain constructor?
Chain constructor is  calling of one constructor from within the other. Say for example : 

public class mySampleClass
{
public mySampleClass(): this(10)
{
// This is the no parameter constructor method.
// First Constructor
}
public mySampleClass(int Age) 
{
// This is the constructor with one parameter.
// Second Constructor
}

10. What is Lambda Expression?
It's a method without a declaration, i.e., access modifier, return value declaration, and name. 
List<int> numbers = new List<int>{11,37,52};

List<int> oddNumbers = numbers.where(n => n % 2 == 1).ToList();

11. What is a satellite assembly?
Satellite assemblies are assemblies that are used to deploy language and culture specific resources for an application.

12. Reflection
Used to decide at run time which method needs to be called depending upon the business logic.
object[] param = new object[4];
                            param[0] = xMetaData;
                            param[1] = shipment;
                            param[2] = ShipmentDataRaw;
                            param[3] = manifestHeader;
                            Type type = typeof(BL_ReportsCustom);
                            MethodInfo methodInfo = type.GetMethod(customMethodName);
                            BL_ReportsCustom method = new BL_ReportsCustom();
                            // Invoke the method on the instance we created above

                            methodInfo.Invoke(method, param);
13. Constructor and Destructor

static constructors are only executed when the first object of a class is created and are executed from child to parent.
Constructors are executed like parent to child way
Destructors are executed from child to parent way. 

14. Idispose
15. Abstraction Vs Encapsulation
16. ref and value keyword. If a class object is passed as without ref keyword what happens
17. Threading? how to create thread.
18. Delegate
19. Event


Monday, June 22, 2015

Interview Questions SQL Server

SQL Server

1. Index Type in SQL server
  • Clustered 
    • 1 Clustered Index is allowed per table
    • Data in the table physically get arranged
    • Index added on column that are searched more
    • Leaf node of clustered index contains data pages
  • Non Clustered
    • Upto 249 per table
    • Create a separate list of key values with pointer to the location of data
    • Logical order of the index does not match the physical order of row
    • Leaf Node does not contain data pages, instead it contains index rows
2. Difference between primary key and unique key.
  • Primary key cannot have null value, where as unique key can have null value.
3. How to find which index is applied on table
  • sp_helpundex table_name
4. Difference between truncate and delete
  • Delete keep the lock on the row, where as truncate keep the lock on table not on the row.
  • In truncate we cannot not roll back, where as in delete we can roll back
5. How to handle Multi Transaction SQL
    Begin Transaction One
    Begin Try
         Delete from tblUSPSMShipment
         
    End Try
   Begin Catch
        If @@Trancount > 0
           RollBack Transaction One
      Print 'Catch'
   End Catch

   If @@TranCount>0
           Commit Transaction One
           Print 'success'
           
           
   Begin Transaction Two
    Begin Try
         Delete from tblUSPSMShipper
         
    End Try
   Begin Catch
        If @@Trancount > 0
           RollBack Transaction Two
      Print 'Catch'
   End Catch

   If @@TranCount>0
           Commit Transaction Two
           Print 'success'

6 Error Handling in SQL Server
   The two most common mechanisms for error handling in SQL Server 2005 are:
  • @@ERROR
  • TRY-CATCH Block
7. Data Reader Vs DataSet

SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
con.Open();
SqlCommand cmd = new SqlCommand("select UserName,LastName,Location from UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gvUserInfo.DataSource = ds;
gvUserInfo.DataBind();



using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"))
{

con.Open();
SqlCommand cmd = new SqlCommand("Select UserName,LastName,Location FROM UserInformation", con);
SqlDataReader dr = cmd.ExecuteReader();
gvUserInfo.DataSource = dr;
gvUserInfo.DataBind();

  • The ExecuteNonQuery() method executes a Transact-SQL statement against the connection and returns the number of rows affected.
  • The ExecuteScalar() method returns a single value from a database query.
  • The ExecuteReader() method returns a result set by using the DataReader object.

8. How can we achieve  Many to Many relationship
Yes, with the help of a 3rd table(junction table) where we will include primary keys from both table between which Many to Many relationship has to be maintained to from Composite key

9. Get a null and make it blank in sql server joiin