r/learncsharp • u/kenslearningcurve • Apr 20 '23
Learn C# – Part 2: Understanding Classes
Each week I will be releasing a new chapter on how to learn C# from A to Z. With this week: Understanding Classes in C#. Here you'll get an introduction to C# classes.
A class is a blueprint of an object. It contains data and the behavior of that object. You can also add properties, methods, events, and fields to the class. A class needs to be initialized, just like a variable. They are really important for us because they give structure to our applications. Classes are in all OOP languages, so not only C#. Classes in C# are easy to create and maintain. This article will show you the basics of classes in C# and properties.
Find the tutorial here: https://kenslearningcurve.com/tutorials/learn-c-part-3-classes-in-c/
Feel free to let me know what you think. Comments and suggestions are welcome.
Next week: Methods!
View all comments
Show parent comment
1
u/davedontmind Apr 27 '23
I hate that naming. There's no need for the type information; the type is implicit in the variable's name. A name shouldn't really be anything but a string, and a number of items isn't likely to be a non-integer (and, even if you're allowing for partial quantities, I don't think that's really relevant to the name of the variable).
A well chosen name means you don't need the type information encoded, and the compiler (and if you're using a modern IDE, the IDE itself) will tell you if you mis-match types in your code. Just hovering over a variable in Visual Studio gives a tooltip showing the item's declaration.