Software
C# Tutorial For Beginners
Software Basics - Part 3
C# Tutorial

Here we introduce some more of the basics of software and start to introduce some of the elements of Visual Studio that will help you understand the tutorials.

Functions

Functions allow you to group a set of instructions together, then whenever you want to perform them repeatedly or at different times you can just call the function again. You can also send values to a function so that it works differently each time you call it.

Here's an example of a function being called:

MyFunction1();

This then sends the program to another part of the code, that can be somewhere else, even another file. The program will find that function and execute it (i.e. run that bit of code, not kill it).

Here's how the function is defined:

MyFunction1()
{
    action1;
    action2;
}

The two actions are performed every time MyFunction1 is called. This avoids you having to repeat the code if you want to do the same thing a number of times.

A function can also take parameters to do something different each time it is called. For example to square a value, 5 in this case, you would call a function:

MySquareFunction(5);

The function is defined as follows:

void MySquareFunction(int a)
{
    int x;
    x = a * a;
}

The x is set to the result, 25 in this example if you've not already guessed.

There's not much point in just multiplying a number by itself unless you do something with the result. To get the result back to the caller, return values are used. In the previous example the function did not return anything, this is why there is a keyword called 'void' before the definition. The 'void' means don't send anything back. In order to create a function that returns a value just replace the void with the type of the value you want to return and then use the 'return' keyword. Here's an example of a more useful square function:

int MySquareFunction(int a)
{
    int x;
    x = a * a;
    return x;
}

To get the value back from the function when you call it just assign the result of the function to a variable as follows:

int result;
result = MySquareFunction(5);

The variable 'result' will be set to 25 in this case.

Objects And Classes

In order to break up and organise the logic of software programs the concept of objects is used.

Many procedural languages, such as 'C', BASIC and Fortran, make use of procedures (functions) to structure the logic and data. This works well for simple programs but can soon become complex.

Object oriented programming introduces the idea of encapsulation of data and functions into logically arranged objects. Data is applicable to the object it is part of and functions are limited to operating with the object it is part of.

C# Is an object oriented language that makes full use of the benefits this brings. It also provides the user with many pre-written classes so that you don't have to re-invent the wheel.

The software code that describes how an object works is usually referred to as a 'class' and when it is declared in code it is referred to as an 'object'. Making an object from a class is called instantiation (i.e. making an instance) and is similar to declaring variables.

Input And Output

Coming Soon!

Compilers, assemblers and linkers

Coming Soon!

Forms

Coming Soon!

Projects

Coming Soon!

          Previous   Next