Difference between Structure (Struct) and Class
Difference between Struct and Class
8) Structure couldn't have a destructor such as class
9) By default,the members of structures are public while that for class is private
· Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap.
· Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface.
· Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.
Labels : SessionState , ViewState , Encapsulation , Abstraction
Labels : SessionState , ViewState , Encapsulation , Abstraction
1) Classes are reference types and structs are value types.
Since classes are reference type, a class variable can be assigned null.But we cannot assign null to a struct variable, since structs are value type.
Since classes are reference type, a class variable can be assigned null.But we cannot assign null to a struct variable, since structs are value type.
2) When you instantiate a class, it will be allocated on the heap.When you instantiate a struct, it gets created on the stack.
3) You will always be dealing with reference to an object ( instance ) of a class. But you will not be dealing with references to an instance of a struct ( but dealing directly with them ).
4) When passing a class to a method, it is passed by reference. When passing a struct to a method, it’s passed by value instead of as a reference.
5) Classes can have explicit parameterless constructors. But structs cannot have
6) Classes must be instantiated using the new operator. But structs can be
7) Classes support inheritance.But there is no inheritance for structs.
( structs don’t support inheritance polymorphism )
classes are used for complex and large set data. structs are simple to use.( structs don’t support inheritance polymorphism )
8) Structure couldn't have a destructor such as class
9) By default,the members of structures are public while that for class is private
class MyClass
{
int myVar = 10; // no syntax error.
public void MyFun()
{
// statements
}
}
struct MyStruct
{
int myVar = 10; // syntax error.
public void MyFun()
{
// statements
}
}
Subscribe to:
Post Comments (Atom)
Labels
- Abstraction in Object Oriented Programming (OOPS) Concept (1)
- Access ChildControls in Gridview using Javascript (1)
- Add a WCF Service Reference to the Client (1)
- ASP.Net GridView Highlight Row onmouseover (1)
- ASP.NET View State And ViewStateEncryptionModes Overview (1)
- Calling Javascript From Any Part Of Code Behind Page By Registering The Script (1)
- Check And UnCheck CheckBoxes In Gridview using javascript (1)
- contact your server administrator. (1)
- DataControlField class (1)
- DataKeys ID (Identity Column) in Child Controls events in GridView (1)
- DataList Paging With PagedDataSource (1)
- Declaring Session in Asp.Net (1)
- Difference between Struct and Class (1)
- Displaying Images In GridView From DataBase (1)
- Dynamic Sitemaps in ASP.NET (1)
- Err: You must install Office SharePoint Server 2007 – Please read Microsoft Knowledge Base article: 962935 with the most recent service pack (1)
- GridView Class (1)
- Gridview Inside GridView (1)
- Gridview Paging using C# (1)
- Gridview Sorting Using C# (1)
- GridView.RowDataBound EventEvent (1)
- GridViewRow (1)
- Inserting Images To Database And Display in GridView (1)
- Microsoft Office Sharepoint Server 2007 on Windows Server 2008 – This Program is blocked due to compatibility issues (1)
- ModalPopUp Using CSS and Div To Reduce the Weight On WebPage (1)
- Session State in Asp.Net OverView (1)
- SharePoint 2010 – The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information (1)
- Tooltip GridView Header (1)
- Tree View Menu Control (1)
- WCF Service (12)
- What is Encapsulation in OOPS? (1)
Topics
- Abstraction in Object Oriented Programming (OOPS) Concept (1)
- Access ChildControls in Gridview using Javascript (1)
- Add a WCF Service Reference to the Client (1)
- ASP.Net GridView Highlight Row onmouseover (1)
- ASP.NET View State And ViewStateEncryptionModes Overview (1)
- Calling Javascript From Any Part Of Code Behind Page By Registering The Script (1)
- Check And UnCheck CheckBoxes In Gridview using javascript (1)
- contact your server administrator. (1)
- DataControlField class (1)
- DataKeys ID (Identity Column) in Child Controls events in GridView (1)
- DataList Paging With PagedDataSource (1)
- Declaring Session in Asp.Net (1)
- Difference between Struct and Class (1)
- Displaying Images In GridView From DataBase (1)
- Dynamic Sitemaps in ASP.NET (1)
- Err: You must install Office SharePoint Server 2007 – Please read Microsoft Knowledge Base article: 962935 with the most recent service pack (1)
- GridView Class (1)
- Gridview Inside GridView (1)
- Gridview Paging using C# (1)
- Gridview Sorting Using C# (1)
- GridView.RowDataBound EventEvent (1)
- GridViewRow (1)
- Inserting Images To Database And Display in GridView (1)
- Microsoft Office Sharepoint Server 2007 on Windows Server 2008 – This Program is blocked due to compatibility issues (1)
- ModalPopUp Using CSS and Div To Reduce the Weight On WebPage (1)
- Session State in Asp.Net OverView (1)
- SharePoint 2010 – The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information (1)
- Tooltip GridView Header (1)
- Tree View Menu Control (1)
- WCF Service (12)
- What is Encapsulation in OOPS? (1)
0 Responses to “Difference between Structure (Struct) and Class”
Post a Comment