Wednesday 21 May 2014

Difference between Value Type and Reference Type :



Difference between Value Type and Reference Type :
Value type
Reference type
Value type they are stored on stack
Reference type they are stored on heap


Value type store real data
Reference type store reference to the data.
Value types are faster in access
Reference types are slower in access.
Value type consists of primitive data types, structures, enumerations.
Reference type consists of class, array, interface, delegates
Value types derive from System.ValueType
Reference types derive from System.Object
Value types cannot contain the value null.
Reference types can contain the value null.
Memory is allocated at compile time
Memory is allocated at run time

Difference between Array and ArrayList

Arrays
ArrayLists
These are strong type collection and allow to store fixed length
Array Lists are not strong type collection and size will increase or decrease dynamically
In arrays we can store only one datatype either int, string, char etc…
In arraylist we can store all the datatype values
Arrays belong to System.Array namespace
Arraylist belongs to System.Collection namespaces
Difference between Virtual method & Abstract method :-

Virtual Methods
Abstract Method
1- Virtual method has an implementation
1- Abstract method does not provide an implementation
2-Virtual method provide the derived class with the option of overriding it.
2-Abstract method forces the derived class to override it.
3- Virtual methods scope to members only.

3- Abstract method's scope to members and classes

What are differences between Array  and Hash table:-
      Hash Table
             Array
1- Hash table store data as name, value   pair.
1- While in array only value is store
2- To access value from hash table, you need to pass name.
2- While in array, to access value, you need to pass index number.

3- you can store different type of data in hash table, say int, string etc
3- while in array you can store only similar type of data.


Difference between  User controls and Custom controls:-
         User Controls
                    Custom controls
1- Compiled at runtime
1- Precompiled
2- HTML design (Visual design possible)
2- No visual design. HTML needs to be declared programmatically
3- We can’t add to toolbox
3- We can add toolbox
4- Good for static layout
4-) Good for dynamics layout
5- A separate copy of the control is required in each application
5- A single copy of the control is required in each application
Abstract class vs Interface:-
             Abstract
                          Interface
1- An abstract class can’t instantiated
1- An interface can’t instantiated
2- An abstract class can implement methods
2- An Interface cannot implement methods
3 An abstract class can inherit from a class and one or more interfaces
3- An Interface can only inherit from another Interface
4- An abstract class can contain fields
4- An Interface cannot contain fields
5- An abstract class can contain constructors or destructors
5- An Interface cannot contain constructors or destructors
6- An abstract class cannot be inherited from by structures.

6- An Interface can be inherited from by structures.

7-An abstract class cannot support multiple inheritance
7- An Interface can support multiple inheritance

Sl. No.
1
Function must return a value.
Stored procedure may or not return values.
2
Will allow only Select statement, it will not allow us to use DML statements.
Can have select statements as well as DML statements such as insert, update, delete
etc
3
It will allow only input parameters, doesn’t support output parameters.
It can have both input and output parameters.
4
It will not allow us to use try-catch blocks.
For exception handling we can use try catch blocks.
5
Transactions are not allowed within functions.
Can use transactions within Stored procefures.
6
We can use only table variables, it will not allow using temporary tables.
Can use both table variables aswell as temporary table in it.
7
Stored procedures can’t be called from function.
Stored Procedures can call functions.
8
Functions can be called from select statement.
Procedures can’t be called from Select/Where/Having etc statements. Execute/Exec
statement can be used to call/execute stored procedure.
9
UDF can be used in join clause as a result set.
Procedures can’t be used in Join clause

Stored Procedure  vs  Triggers:-
      Stored porcedure
           Triggers
1- Stored Procedure may Return a value
1- Trigger not return value
2- In Stored Procedure you can pass parameter
2- in trigger you can't pass parameter
3- We explicitly call the Stored Procedure
3- Trigger are implicitly fired
4- Stored procedures are used for performing tasks
4- The Triggers for auditing work
5- Stored Procedure is written for an Database
5- Trigger written on an individual Table or View.
6- We can use transaction statements like begin transaction, commit transaction, and rollback inside a stored procedure
6- we can't use transaction statements inside a trigger
7- We can use Print commands inside a stored procedure for debugging purposes
7- we can't use print commands inside a trigger.
8- We can execute a stored procedure whenever we want with the help of the exec command
8- trigger can only be executed whenever an event (insert, delete, and update) is fired on the table on which the trigger is defined.


Var   vs Dynamic:-
           Var
                          Dynamic
1- It is a keyword that is used for implicit variable declaration at compile time.
1 It is a keyword used for variable declaration at runtime.
2- var cannot be used to declare variables at class level.
2- dynamic can also be used to declare class level variables.
3- var cannot be used as the return type of methods.
3- dynamic can also be used as return type of the methods.

Constant   vs   Readonly:-
     Constant
       Readonly
1-  Value is evaluated at compile time.
1-  value is evaluated at  runtime .
2- Can be declared as class member or inside a method.
2- Is not allowed inside a method.
3- Is always static.
3- Can be static or instanceable.
4- Can only be initialized at declaration.
4- Can be initialized at declaration or in the constructor

Temporary Table    vs   Table Variable:-
   Temporary Table
    Table Variable
1- Syntax-  create  table  #temp
1-Syntax- Declare @tablename Table
2-It support DDL operation :-like drop,create, alter etc.
2- It doesn’t support DDL operation.
3-It participate the explicitly transactions defined by the user.
3- It doesn’t  participate in the explicit transactions defined by the user.
4- It doesn’t allowed in  UDF
4- It can be used in user defined functions
5- It support adding indexes explicitly after table creation.
5-It  doesn’t  adding indexes explicitly.

Response. Redirect  vs     Server. Transfer:-
  Response. Redirect
  Server. Transfer
1-It involues a round trips to server
1-It doesn’t involves a round trips
2- It redirect to an external server.
2-It redirect to only same server.
3- It used for both .aspx and html pages
3- It used for only .aspx pages.
4-  We can’t preserve our information
4- We can preserve our information.

Truncate vs Delete:-
     Truncate
     Delete
1-Truncate is a DDL operation.
1-Delete is a DML operation.
2-Truncate is faster.
2-Delete is slow.
3- Truncate reset the identity column value.
3- Delete can’t reset identity column value.
4-We can’t use condition in truncate.
4- We can use condition in delete
5-We can’t rollback in truncate.
5- We can rollback in delete.

String
StringBuilder
It’s an immutable
It’s mutable
Performance wise string is slow because every time it will create new instance
Performance wise stringbuilder is high because it will use same instance of object to perform any action
In string we don’t have append keyword
In StringBuilder we can use append keyword
String belongs to System .string namespace
Stringbuilder belongs to System.Text .stringbuilder namespace
Process vs Thread:-
                  Process
                      Thread
1- Process - executes single program.
1- It used to execute more than one program at a time.
2- process is a collection of threads that share the same virtual memory
2- A thread is a path of execution that run on CPU
3- A process has at least one thread of execution
3-thread always run in a process context.
4- A process is considered as “heavyweight”
4- while a thread is deemed as “lightweight”.


           Machine.Config
         Web.Config
1- This is automatically installed when we install .Net Framework.
1- This is automatically created when we create an ASP.Net web application project.
2- Only one machine.config file exists on a server/computer.
2- more than one web.config  exists in a web
 Application project.
3- This is also called machine level configuration file.
3- This is also called application level configuration file
4-  With out the Machine.Config file Application can not be executed
4- With out the Web.Config file Application can still be executed.

        Primary key
        Foreign Key
1- Primary key uniquely identify a record in the table
1- Foreign key is a field in the table that is primary key in another table
2-  Primary Key can't accept null values
2- Foreign key can accept multiple null value.
3- We can have only one Primary key in a table.
3- We can have more than one foreign key in a table

            Where Clause
              Having Clause
1- The WHERE clause cannot contain aggregate functions.
1- The HAVING clause can contain aggregate functions.
2- It can be used without the GROUP BY clause.
2- The HAVING clause cannot be used without the GROUP BY clause.
3- The WHERE clause selects rows before grouping.
3- The HAVING clause selects rows after grouping.


                  Finalize
                  Dispose
1- Finalize () belongs to the Object class.
1-Dispose() belongs to the IDisposable interface
2-It is automatically called by the Garbage Collection mechanism when the object goes out of the scope.
2-We have to manually write the code to implement it(User Code)
3-It is slower method and not suitable for instant disposing of the objects.
3-Faster method for instant disposal of the objects.
4-It is non-deterministic function
4-It is deterministic function as Dispose() method is explicitly called by the User Code

Throw ex

In Throw ex, the original stack trace information will get override and you will lose the original exception stack trace. I.e. 'throw ex' resets the stack trace.

Throw

In Throw, the original exception stack trace will be retained. To keep the original stack trace information, the correct syntex is 'throw' without specifying an exception.




     Master pages
        User Control
1- It can be designed one language and used for the webpage supported all the language.
1-Desined user control in one language and can’t used all supported language.
2-Master page can be assigned in web.config file so that the web pages in the project will automatically use master page.
2-It must be registered in each and every web page, where it has to be used.
3-Master page can be used for web page within a specific folder by declaring a web.config file for that.
3- There is no scope to use the user control to a web pages within a specific folder or project like  master page.
4-Master page contents in the content page will be displayed while working with the application.
4-User Control contents will not be displayed during design time.
5-Duplication of templates is not possible with the master pages.
5-There is a possibility of duplication in web pages with the User Controls.