.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML
ETG Consultancy
As we know depend on memory location datatypes are mainly categorised
into two section; reference type and value type
| Refference type |
Value type |
| String, class |
int, srtuct, date |
Major difference between Class and struct
| Class support inheritence |
Structs doesnot support inheritence |
Calss supports any type of constructor
class ETGTeam
{
public ETGTeam()
{
}
public ETGTeam(int TeamId)
{
}
}
|
Struct doenot support any constructor without any parameter.
struct ETGTeam
{
public ETGTeam() // This is invalid in constructor
{
}
public ETGTeam(int TeamId) // This is invalid constructor
{
}
}
|
| Class is reference type (memory location heap) |
Struct is value type (memory location stack) |
| The "new" keyword create a new instance (memory location) of
class type object. |
for struct the "new" keyword work differently, instead of allocation a new
memory location that simply calls the default constructor.
if the struct object is not fully initialised , it wont allow to compile the
code. |
Advantage and disadvantage of using struct object :
as we know retriving data from stack is very fast, so where the object
is being fetched straightly, there using struct is always a good idea.
disadvantage is when struct object is assigned to another struct object, the
full content of that struct is being copied is duplicated and added to the
stack. thus can hit the performance.
|
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML