- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Articles
- What are the differences between a class and struct in C#?
- What are the differences between a static and a non-static class in C#?
- What are the differences between class methods and class members in C#?
- What are the differences between struct and class in C++?
- What are the differences between a class and an interface in Java?
- Difference between Class and Structure in C#
- What are the differences between an Exception class and an Error class in Java?
- What are the differences between a dictionary and an array in C#?
- What are the differences between a pointer variable and a reference variable in C++?
- In C++ What are the differences between a pointer variable and a reference variable?
- What is the difference between class and structure in Swift?
- What are the differences between C++ and Java?
- What are the differences between C and Java?
- What are the differences between C++ and Go?
- What are the differences between a list collection and an array in C#?
