Difference between class and structure | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Difference between class and structure

I came from the knowledge of C. Now that I am learning about Classes in C#, they just look the same as a structure in C. Are they the same thing?

10th Apr 2018, 11:15 PM
Arthur Boss
Arthur Boss - avatar
3 Answers
+ 3
No they are not. Structs are primitive version of classes. Class is from OOP terminology. You should learn about OOP to understand what classes are. There are a lot of things that you probably won't understand without knowing what object oriented programming is. The access to vars in struct are public default, but in class they are private.
10th Apr 2018, 11:25 PM
Bartosz Pieszko
Bartosz Pieszko - avatar
+ 2
If you pass a class as an argument it is passed by reference, if you pass a struct as an argument it is passed by value.
10th Apr 2018, 11:41 PM
Kevin Eldurson
Kevin Eldurson - avatar
+ 1
Simply structure is procedural language or structure Oriented language. Whereas class is object oriented language. The both are different. If you want to know about the classes and how they declare better to learn OOP's concept. Then you can simplify all this.
29th Sep 2019, 11:53 AM
Sankar Rao Mudadla
Sankar Rao Mudadla - avatar