C Sharp Basics:
- Part 1: Class Anatomy
- Part 2: Public and Private Variables
- Part 3: Methods
- Part 4: Thinking in Objects
C# is a multi-paradigm programming language created by Microsoft as part of the .Net initiative in 2000. It has gone on to have its own standard and become part of everything from desktop applications to used extensively in game development.
Class Anatomy
C# expects classes. In programming terminology, a class is some set of instructions that defines an object of some kind. It is the digital representation of an idea in object form.
A C# file is named after its contents. A “main.cs” will contain the “MainClass” or a class named “Main”. Such an organizational scheme helps with managing files and lets developers know that files match the classes they contain.
What are you using?
Like many other languages, C# supports external modules that extend or provide different functionality. When looking at a C# class, it will often be “using” other libraries or files. This means that the class references something those other files contain.
Through the using keyword and the name of the library or file, it can be included in the file and its functionality used. This allows for a very modular approach to programming where short packages can solve small problems and allow any one single class to only include what it needs to function.
What is the class?
C# expects classes. Since files contain classes, often the next part of code after the using keyword usage will be the class name. This is the digital object described in this file.
Defined with the keyword class and its name, everything in the file will nearly always be “in” the class. It’s opening and closing curly brackets will extend around all of its parts and enclose them as part of itself.
What are its parts?
Nearly always, a class will have some type of internal parts. Be this variables, methods, or a combine of the two, the digital object will have some way of doing or being something.
The internal parts of a class are “inside” the curly brackets of the class and defines itself and any connections to other objects. This functionality can come in many different forms, but describes the object and its relationships.