- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the differences between a class and a structure in C#?
Structure
In C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.
To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program.
Classes
When you define a class, you define a blueprint for a data type. A class definition starts with the keyword class followed by the class name, and the class body enclosed by a pair of curly braces.
Structure vs Classes
Structures are value types and the classes are reference types.
On passing a class to a method, it is passed by reference. But when a structure is passed to a method, it is passed by value.
Classes supports Inheritance but this is not the case with structure.
Destructor in a class can be used but in Structure, you cannot use a Destructor.
Structures cannot have default constructor