C# from beginner to advanced - tutorial #001
Hi! I’m currently start with my first series of tutorials in Steemit. I started programming seven years ago (with some breaks) and today I know C# on intermediate level. Thanks to my high school teacher I decided to get knowledge about programming through teaching others people. I hope that during this series of tutorials you will learn about C# from basics of writing code to more advanced and powerful solution.
In this tutorial I will use Visual Studio 2017.
Basics:
C# is object-oriented language. That means that does not offer global variables and functions. Everything is contained in classes. But what are classes? Class is definition of object. For example we can get a class named Apple. In our program can be a lot of objects that are instances of this class. First we must create our object:
Apple apple = new Apple();
Additionally each one of them have own attributes (color, shape, weight). They are all defined in class, so if you want edit them you must get object and set its attribute. For example to change weight of our apple (for example to 2kg) you must write:
apple.weight = 2;
But before we start work with classes we should learn about our program structure. To create new project in VS (Visual Studio) chose File -> New -> Project… -> Console App (.NET Framework). We should see:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProgramName
{
class Program
{
static void Main(string[] args)
{
}
}
}
Ok, so let me explain what this mean.
First we have using System;
(and some other similar to this). The using keyword is used to include new namespaces to our project.
Next we have namespace ProgramName { … }
– it’s a collection of classes that we will create.
class Program {…}
it’s our first class. It contain the data and method that our program uses.
Inside Program class we have static void Main(string[] args) {…}
. Exactly here our program will started. The Main method states what the class does when executed.
When we know primary construction of our program we can write some code. Inside Main method type
Console.WriteLine("Hello World!");
Console.ReadLine();
WriteLine
is a method of the Console
class defined in the System namespace. This causes the message in bracket to be displayed on the screen.
Console.ReadLine()
makes the program wait for a key pressed. This prevent the screen from running and closing quickly when the program is launched.
To launch program click the Start button (or press F5 key).
It’s all! You should be able to see Command Prompt window appears that contains the line “Hello World”.
Sorry for my English. I try to do my best, but I'm still making mistakes.
good stuff bruh