Thursday, 17 April 2014

Beginner's C# Course, Part 1

The basics of C#: OOP

What is OOP?
OOP stands for "Object Oriented Programming" and is a term used to describe programming languages such as C# or Java, who's entire code structure depends on everything being derived from some form of "Object"

In C#, code is written into files suffixed *.css (C Sharp Source not Counter Strike: Source). These are most commonly made as "classes" (although sometimes made as "interfaces", but that's a different topic). Classes are how you define your own types of objects. (For examples, integers, Strings, booleans etc are all types of objects. Whenever you define a variable, that variable needs an object type, so it knows what it's supposed to be.
Here's how most classes are structured:

##File Start##
//Using Statements go here
using system
using system.blah

using mycode.myclass

//You declare the namespace here
namespace mycode
{

        //and here we name the class
class myclass2returnoftheclass
{
                //Your class code goes here
                public myclass2returnoftheclass()
                {
                        //Your constructor code goes here
                }
        }
}
##File End##

But what does all this mean? What's a namespace? What's a constructor?
Well, constructors we'll get onto in the next part of the course, as for a namespace, they're akin to packages in Java.

A namespace is how you organize your code. Generally, all code for a certain program comes under one namespace, and then things such as input from other programmers and mods usually go in sub-namespace.

For example, let's say I make a program called "appy"
I would use the namespace appy
So if the main class file was main.css, the code directory of it would be appy.main
And if another programmer made a mod called smartappy, it would probably come under appy.smartappy

Anyway guys, that's pretty much it for the first part. Next part coming on saturday :D

No comments:

Post a Comment