C # classes

C # classes

Classes are a reference type. So they essentially tell the program that this set of constructors, methods, etc is associated with this object. So a class is really the blueprint for a object you are making, whether that object is in another class or is embedded in the class.

In C# there are namespaces which are essentially groups of classes. Most of these namespaces are for classes that the language gives such as System, which has the Console class in it. You can of course make one yourself. If you are using methods from a different class make sure to import it or have your class inherit it. I will talk more about this in a different post which I will link, If I remember.

So you use classes by creating a object that has that class as its type. For example:

Meclass whatever = new Meclass();

So it’s: NameOfClass NameOfObject = CallConstructore();

With the constructor call being new NameOfClass(VariableThatMatchesAConstructor)

You create a class by doing:

public class ClassName

{

//methods,constructors global variables, etc

}

So ‘public’ would be the access-modifier (will hopefully make a post on this too but for now you can look at Microsoft docs aka where I get most of my information on C#), the rest is fairy self explanatory.

One thought on “C # classes

Comments are closed.