Learn to Code via Tutorials on Repl.it!

← Back to all posts
Part 1 c# tutorial: The var menace
Bunnytoes (147)

Here is a c# tutorial made my me

lets start with the basics, every program starts with this:

using System;

class MainClass {
  public static void Main (string[] args) {

Make sure to end the code with the relevant amount of } curly brackets.

// means a comment and doesn't do anything

To write a line you type this, Console.WriteLine("");
put your text into the "" quotations, try that. Now for variables, the type of variables are

int float double decimal long var bool char string

an int is a whole number. a float is a number that can have decimals or not and it can have some decimals. a double is similair to a float but it can handle a certain amount of decimal places like float. a decimal can contain a bunch of decimal places. a long is I don't remeber similair to a float and a double. typing var has the computer figure it out but this uses for processing power and you may forget what you are doing. a bool is true of false. a char is 1 character like a and a string is a string f chars

if you want to get and store data you can do 2 things,
have them enter text

Console.WriteLine("Enter your name");

then you can do this

string  name = Console.ReadLine();
//anything you want

and then you have it stored, or you can create a variable at the beginning

using System;

class MainClass {
public static void Main (string[] args) {
string hello;
Console.WriteLine("Enter your name");
name = Console.ReadLine();

and now the data is stored, but what if you want it to be a number?
you can use convertion methods to do that, so instead of putting string you can do this,

int name = Convert.ToInt32(Console.ReadLine());

and bam! now it's an int
you can also use a float.Parse method like the ToInt32 method, you can do Convert.ToDouble or at the end of the part you can convert it to a string by doing .ToString();
make sure to end each statement with a ;
and to write a variable you do this:


enter the variable name into the parenthases
so thats the basics and I will continue to make tutorials and I'll see you in the next one
You can also finish decimals with the letter m and floats with the letter f

this is the part one please don't unlist mods

CodeLongAndPros (1624)

The title looks familiar...

Bunnytoes (147)

@CodeLongAndPros got it from you :p(The names are great)you didn't unlist this, right?