C Sharp Basics: Part 1: Class Anatomy

C Sharp Basics:

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.

Screenshot 2018-10-08 15.31.41

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?

Screenshot 2018-10-08 15.34.00

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?

Screenshot 2018-10-08 15.37.36

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?

Screenshot 2018-10-08 15.40.27

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.

Play with the example on Repl.it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s