Important differences in .net programming for beginners


In this article am going to list out the important differences in .net programming. Like dispose and finalize, constructor and destructor, abstract class and interface, string and stringbuilder, virtual method and abstract method, encapsulation and abstraction etc.


In this article am going to list out various differences which we come across in .net programming.
This article is mainly useful for beginners who have confusion on various terminologies present in dot net programming.




1.Difference between dispose and finalize?

Dispose:

*Dispose method is called explicitly by the developer through IDisposible interface to remove object forcefully.
*It is used to clear unmanaged resources means which are not in control of CLR.
Finalize:

*Finalize method is called implicitly called by garbage collector to remove object which is not in use.
*It is used to clear managed resources means which are under control of CLR.

2.Difference between value type and reference type?

Value type:

*Value type contains data directly.
*There is no default vale assigned.
*Stored in stack at compile time.
*Ex- predefined data types,enums etc.
Reference type:

*Reference type contains address not data.
*Default value is assigned.
*Stored in heap at run time.
*Ex- classes,arrays,objects etc.

3.Difference between boxing and unboxing?

Boxing:

*Converting value type to reference type is boxing.
*It is implicit type casting.
*Ex- int i=10;
object x=i;
Unboxing:

*Converting reference type to value type is unboxing.
*It is explicit type casting.
*Ex- object x=10;
int i=(int)x;

4.Difference between constructor and destructor?

Constructor:

*It is a method executed automatically when we create an object.
*Constructor name must be same as class name.
*Constructors are overloadable and does not have return type.
Destructor:

*It is a method executed automatically when object is destroyed.
*Destructor name must be same as class name.
*Destructors are not overloadable and does not have return type.

5.Difference between string and stringbuilder?

String:

*String is said to be immutable because we cannot change after string object is once created.
*If we try to change the value of string object, another new string object is created with modified value.
*Every time we change value a new object is created.
Stringbuilder:

*Stringbuilder is said to be mutable because we can change value after object is created.
*Changing the value will not create new object instead existing value is modified.
*Every time we change value a new object is not created.

6.Difference between overloading and overriding?

Overloading:

*Having same name for two or more methods with different arguments is called overloading.
*It is also called as early binding.
Overriding:

*Having same name for methods in base class and derived class with same arguments is called overriding.
*It is also called as late binding.

7.Difference between stream reader and stream writer?

Streamreader:

*This is used to read data from files.
*It has following methods
Read();
ReadLine();
ReadToEnd();
Streamwriter:

*This is used to write data in to files.
*It has following methods
Write();
WriteLine();
Flush();

8.Difference between encapsulation and abstraction?

Encapsulation:

*Writing all members and member functions together which is also called as data binding is called encapsulation.
Abstraction:

*Hiding the data which is hiding complexity with the help of access modifiers is called abstraction.

9.Difference between abstract class and interface?

Abstract class:

*Abstract class can contain both abstract methods and non abstract methods.
*If a class contains at least one abstract method then that class must be declared as abstract class.
*Abstract class can inherit from another abstract class and can inherit from more than one interface.
*Abstract methods must be implemented in derived class.
*Object cannot be created for abstract classes, reference can be created.


public abstract class myabstract: IA, IB //IA and IB are two interfaces
{
public abstract viod m1(); //abstract method
public void m2() //non abstract method
{
//some logic
}
}

Interface:

*Interface contain only abstract methods, which are public abstract by default.
*Interface can implement another interface but cannot implement abstract class.
*Object cannot be created for interface, reference can be created.

public interface ISample:IMysample
{
void mymethod();
void mymethod2();
}


10.Difference between Abstract method and virtual method?

Abstract method:

*When a class contains at least one abstract method then class must be declared as abstract class.
*Abstract method does not have body.
*Abstract methods should and must be overridden in derived class.
*Implementation of abstract methods must be provided in derived class.
Virtual method:

*A class can contain virtual method.
*Virtual method contains body.
*When we inherit a class that contain virtual method, we can override that method or we can change the logic of virtual method in derived class.


Comments

Author: sridhar thota03 May 2015 Member Level: Gold   Points : 5

Difference between call by value and call by reference?
Call by Value:
1.When formal arguments are modified and that modifications are not affected on actual arguments is called call by value.
2.By default all variables we use are passed by value.

Call by Reference:
1.When formal arguments are modified and that reflects actual arguments is called call by reference.
2.Ref keyword should be used with actual and formal arguments.

Difference between Web.Config and Machine.Config?
Web.Config:
1.Web.Config provides website level settings.
2.It should be created by developers.
3.We can have more than one Web.Config files.

Machine.Config:
1.Machine.Config provides webserver level settings which are applied to all websites.
2.It will get created while installing .Net software.

Sridhar.
DNS Member.
"Hope for the best.. Prepare for the worst.."

Author: sridhar thota06 May 2015 Member Level: Gold   Points : 5

Difference between Dock and Anchor?
Dock:
This property is available for all controls.
Dock property of a control changes the size of control based on windows form size.

Anchor:
This property is available for all controls.
Anchor property changes the location of control based on windows form size.

Difference between DataReader and Dataset?
DataReader:
1.DataReader works only when connection is open.
2.DataReader read records in forward direction only.
3.DataReader is connection oriented, when connection is close DataReader will be closed automatically.
4.DataReader holds a collection of records.

Dataset:
1.To work with Dataset open connection is not required.
2.Dataset can read records in both directions.
3.Dataset is not connection oriented.
4.Dataset holds collection of tables.

Sridhar.
DNS Member.
"Hope for the best.. Prepare for the worst.."



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: