
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Difference between Class and Structure in C#
In order to differentiate between Class and Structure, we have to first understand that both structure and class seems to be equivalent in the context of holding and defining the data. Both of these could define as well as hold some default values in their data members. But if we consider them beyond this context then Class provides more flexibility along with functionality as compared to the Structure.
Following are the important differences between Class and Structure.
Sr. No. | Key | Class | Structure |
---|---|---|---|
1 | Data Type | Data defined in a class is stored in the memory as a reference and has particular address in order to get accessed, so it could be stated as Classes are of Reference type. | On other hand in case of Structure the value of data member gets stored directly either in the stack or inlined containing types so Structures are considered as of Value type. |
2 | Storage | As mentioned in above point, the data members are stored as reference in case of Class and reference types are allocated on heap memory. | On other hand in Structure direct value get to be stored so the value types are allocated on stack memory. |
3 | Constructor | Classes can be defined with constructor as well as de-constructor as it has their functionality implemented. | On other hand Structure could not have either Constructor or De-constructor as no such implementation is provided in it. |
4 | Instantiate | As Class introduced with constructor with the help of which Class can instantiate its instance with new keyword. | On other hand Structure can create an instance without new keyword. |
5 | Inheritance | Class can inherit properties from its parent class as it supports the Inheritance feature. | On other hand Structure does not support the Inheritance. |
6 | Protected Modifier | We can use protected modifier with the data members defined in the class as Class supports protected modifier. | On other hand Structure does not support the protected modifier. |
- Related Articles
- Difference Between Structure and Class
- What is the difference between class and structure in Swift?
- Difference Between Structure and Union
- Difference Between Array and Structure
- Difference between Structure and Union in C
- Difference between Structure and Array in C
- Difference between Structure and Union in C Program
- Difference between data type and data structure
- Difference between String class and StringBuffer class in Java
- Difference between namespace and class in C++
- Difference between Object and Class in Java
- Difference Between Object and Class in C++
- Difference Between Class and Interface in Java
- Difference between abstract class and interface
- What are the differences between a class and a structure in C#?

Advertisements