C# FOR BEGINNERS

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

Psycho_Coder

Active Poster
Retired Staff
Active Member
Apr 12, 2014
642
481
133
UK
Just today, I am going to be teaching those noobs some basic c# sharp stuff. Things you will need.:
  • Visual stuido 2010. 2012, 2013
  • a brain


Open a console application in c#
Ok, So let's get started. This si going to nice and short. Let's start off with comments shall we. Comment is the same as in nearly every other programming language. Here is is.

Code:
//Hello world

Knowing that, You are going to need to place this code at the very start because if you don't have this code nothing will run at all. Here is the code.

Code:
using: System;

Now let's move on a class. Now, For me, it is not highly important to have a specific class, as this is not a hight developed tutorial. You can put any.

Code:
class Hello world

Now, because you have got the class there you are now going to want to define it below. You will have to use the "main" function, This is used and tell the computer that you want it to be a program.

Code:
{
static void main(){

}
}

You are now going to want to actually make the program produce the hello world. It should look something like this.

Code:
Console.WriteLine(""Hello world);

Now, let's say you're wanting to exit the program but it does not let you? You would do this.
Code:
Console.WriteLine("Press any key to exit.");
Console.ReadKey();

Let's make sure the windows stays open while we are debug mode.

Code:
//Keep window open in debug mode

Another comment, to show how to run the program

Code:
//Press F5 to run it

Now, This is what the code looks like all together.

Code:
Using system;

class hello world {
static void main() {
console.WriteLine("Hello world");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
//Keep open in debug mode
//Press F5 to run
}
}

You have just created your first program.
 

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Dec 19, 2014
517
380
133
Crunch
Also, For those who are using an Windows Form Application Replace
"console.WriteLine" with "MessageBox.Show"
 
General chit-chat
Help Users
    @ QM|T_JinX: :weed: