Uses of C#:
- Writing web applications to run on web servers
- Cross platform mobile applications
- To build 3d games
File Names:
C# filenames have a ".cs" extension at the end of their file names.
Classes:
When coding we organise code in classes. We can enclose the code inside of a pair of curly braces { code goes here }. Programs can have multiple classes. In object oriented terms a class is a blueprint for creating objects(objects will be covered later). Computer programs can have multiple classes.Classes usually have a name. It can be any almost any name but it must begin with an uppercase letter.
Examples of class names:
- Mammals
- Birds
- Fish
- Amphibians
- Reptiles
- Automobiles
- Doors
- Phones
However you cannot name your class "Class" or any of the following keywords. I guess it may be confusing for the program. Below is a sample of some of the keywords that you cannot use. You can do a google search for more C# keywords.
Abstract
|
Base
|
Bool
|
Case
|
Catch
|
Char
|
Class
|
Const
|
Default
|
Double
|
Enum
|
Event
|
False
|
Float
|
For
|
If
|
In
|
Int
|
Interface
|
Long
|
Object
|
Private
|
Public
|
Short
|
Methods:
Methods are usually found inside classes and they are like a set of instructions. These instructions are also contained in a pair of curly braces { code goes here }. Classes can have many different methods. There are four parts in a method:- Name
- Parameters which are contained between a set of parentheses
- Body which contains our code
- The return type...what will this method return
NB//
- The keyword void means that the method will not return anything.
- The "Main" method is the first method that will run when the program is started and each program must have a main method.
- Calling a method means executing the code inside the method.
- You can call a method from within another method.
Below is an example of a method:
Comments:
Comments are sections of code that the program won't read. We can use these comments to say what different parts of the program are doing so that when we return to the program after it has been completed we won't be completely lost.
Comments in C# begin with two forward slashes:
//This is a comment:
Framework:
This is a large collection of code that can be used to build certain types of software. C# uses the .NET framework which contains many classes and many different methods.Variables:
A variable can be compared to a box which we can store things in. The same way how we may have boxes to store a specific thing we have variables that store different types of things.
Types of variables:
- string
- int (these are whole numbers and they can be positive or negative)
To declare a variable of type string and named "firstName" we type:
1) string firstName;
to assign this variable a value we write:
2) firstName = "Victor";
but steps 1 and 2 could have been done in one step.
3) string firstName = "Victor";
notice the name Victor is enclosed in double quotes. Variable names can contain letters, numbers and underscores but they cannot start with a number.
Variable names are usually written in camel case so that they are easy to read. Variable names should also be descriptive.
No comments:
Post a Comment