+ 3
What is a difference between class and struct?
8 odpowiedzi
+ 6
structs are used to represent a bundle of data(only properties), classes are modelling a complete object with properties and behaviour.
+ 5
Primarily, it's the status/visibility of their members. Class members are private by default, while struct members are public by default.
+ 4
Classes are reference types while structs are value types.
+ 3
struct doesn't allow you to treat it like built in data type but Classes behaves like built in data type.
secondly, you can not hide the data from outside world in struct. But you can do it with classes.
Third, you can not perform normal binary operation like C=A+B with struct. But you can do it with Classes using overloading.
Last, struct doesn't allow us to inherit another struct. And as you know you can do with class.
+ 3
you can have public,private data in class. it is private by default
whereas,in struct you can have only public data. in struct it is public by default..
also cannot inherit from another struct in struct...whereas it is possible in class.
+ 2
classes are collection of data(variables) and methods.
structs are collection of data (variables).
+ 2
class is somewhat like structure. But it has both data members and functions whereas sturucture doesn't have member function.
0
One is reference type another one is value type!