A class is a user-defined blueprint or prototype from which objects are created. Basically, a class combines the fields and methods(member function which defines actions) into a single unit.
The name of the author is : Ankita The name of language is : C# Total number of article published 80 Total number of Improvements: done by author is : 50
A structure is a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types.
Name of brand: Bugatti Model name: Bugatti Veyron EB 16.4 Color of car: Gray
Difference between Class and Structure
|Classes are of reference types.||Structs are of value types.|
|All the reference types are allocated on heap memory.||All the value types are allocated on stack memory.|
|Allocation of large reference type is cheaper than allocation of large value type.||Allocation and de-allocation is cheaper in value type as compare to reference type.|
|Class has limitless features.||Struct has limited features.|
|Class is generally used in large programs.||Struct are used in small programs.|
|Classes can contain constructor or destructor.||Structure does not contain constructor or destructor.|
|Classes used new keyword for creating instances.||Struct can create an instance, without new keyword.|
|A Class can inherit from another class.||A Struct is not allowed to inherit from another struct or class.|
|The data member of a class can be protected.||The data member of struct can’t be protected.|
|Function member of the class can be virtual or abstract.||Function member of the struct cannot be virtual or abstract.|
|Two variable of class can contain the reference of the same object and any operation on one variable can affect another variable.||Each variable in struct contains its own copy of data(except in ref and out parameter variable) and any operation on one variable can not effect another variable.|
- Difference between Abstract Class and Interface in C#
- How to access structure elements using Pointers in C#
- C# | Object Class
- C# | SortedSet Class
- C# | Array Class
- C# | LinkedList Class
- C# | SortedList Class
- C# | Collection Class
- C# | HashSet Class
- C# | StringCollection Class
- C# | Class and Object
- C# | Stack Class
- C# | Queue Class
- C# | Hashtable Class
- C# | Sealed Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.