Learn to Code via Tutorials on Repl.it!

← Back to all posts
C Sharp Tutorial ~ Part 1: The Theoretical Stuff
LiamDonohue (291)

Hello Guys!

It's what I promised!!

Ok, so today I'm going to introduce the theoretical stuff of C# (btw this Will be useful later).


What is a variable anyway?

Well, a variable is a reserved place in your (or in this case, repl's servers) computer's RAM (Ramdom Access Memory), that can be edited.

Types of Variables.

  • bool
    This can only hold 2 values, true or false
  • string
    This can hold multiple alphanumeric and special characters, such as
    "hello world"
  • char
    This can only hold a single alphanumeric character
  • Integer
    This can hold a single numeric value
  • double
    This can hold a single decimal value

    There are TONS more types then this but for the sake of space (and me being lazy lol), I'm not going to list them all.


These are basically just normal variables but they cannot be edited

These are NOT declared normally

const string = "hello";


Ah, everyone just loves these! they are such a pain in the behind


A syntax error is a:

  • spelling error
  • missing character


These are basically mathematical errors or misspelling of variables

You may be wondering: Why? it looks fine

Well, it's not. If you look closer it's simple. You just made a capitalization error


These are nearly undetectable
some signs are:

  • low memory
  • division by zero

Good Programming Practices

- Indentation

- Commenting

//this is a comment

well that's all for now





how is this so popular??


I n e e d m o r e

LiamDonohue (291)

lol u must wait until the weekend lol @TaylorLiang

King597 (3)


Highwayman (1443)

The Journey Begins

LiamDonohue (291)

duh duh duh DUHH duh dun dun DUHHH @Highwayman

Highwayman (1443)

@LiamDonohue ok, imma just hope this works...
Edit: dam :(

partharoo25 (12)

You are a heck of a coder!
Nice skills.

sugarfi (626)

what about segfaults? does c# not have those?

sugarfi (626)

@LiamDonohue segmentation faults? when you do bad stuff with memory and the computer gets mad?

LiamDonohue (291)

oh I'm not sure I've never encountered one @sugarfi

Zwilson1987 (0)

//where do I start without knowing anything? what does each character mean? what would i use to start a brand new page? tia

Highwayman (1443)

@Zwilson1987 this entire comment is made up of characters, to give an example. Actually technically I could store this comment as a string, because it is just a STRING of CHARACTERS. What do you mean By start a brand new page?

Zwilson1987 (0)

Brand new string I meant sorry it’s the special characters and their meanings and where they go is what I’m asking @Highwayman

Highwayman (1443)

@Zwilson1987 well, have you heard of the ASCII alphabet? It’s basically all the characters you can use in a normal char.
Edit: oops sorry that sounds kinda rude sorry bout that. Didn’t mean to be rude. Also you 'start'(declare) a brand new string the same way you do with any other variable:

string v;
Coder100 (17018)

What is a signed value?
Reeeeeee JavaScript never cared about this.....

using System;
using Replit
class Post {
  public static void Main(){
       votes++; learn++; errors--; c++; // < c#
LiamDonohue (291)

eh, I need to correct it lol @Coder100

Highwayman (1443)

@Coder100 a signed value is a value that can be both negative or positive. An unsigned value can only be positive, but it allows for a couple things, like knowing what the fill is when your shifting bits in an integer and being able to represent higher numbers.

Coder100 (17018)

but it allows for a couple things, like knowing what the fill is when your shifting bits in an integer and being able to represent higher numbers. what does that mean? @Highwayman

Highwayman (1443)

@Coder100 well, in order for a number to be signed it must sacrifice a bit to represent the current sign(negative or positive), and since it sacrifices that bit, the highest number it can reach is halved, because of the reduced space. For example, if you have an unsigned Integer that is one byte, it can represent values 0 to 255, but a signed integer represents -127 to 127.
Also, when you do a bit shift on a signed integer( >> or << ), the bits in the msb(most significant bit) will be used to fill in the bits that no longer hold data. This is really hard for me to explain, so Imma use pictures.
Say again I have an unsigned integer that is one byte long. Let’s say it holds the value 255.

11111111 // 255

now when I shift this integer’s bits by 3, the top 3 bits will be emptied(zeroed) out.

11111111 >> 3 // shift bits over by 3
00011111 // now it’s this.

But if I used a signed integer, the first 3 bits will remain unchanged, because the msb( the first bit in this case) is a 1! So instead of the emptied out bits getting filled with 0s, they get filled with 1s!

11111111 >> 3 // shift bits by 3
11111111 // top three bits filled with the msb.

But if the top bit is a 0, then it will get filled with 0s.

01111111 >> 3 // shift bits 3 to the left
00001111 // emptied bits instead filled with 0s

If anything is still confusing, tell me. Idk if any of this makes sense.

LiamDonohue (291)

lol this is ap computer science level stuff xD @Highwayman

Highwayman (1443)

@LiamDonohue mm I don’t know about that. It’s not really hard stuff. 🤷‍♂️

LiamDonohue (291)

ik its just bits and bytes @Highwayman

Highwayman (1443)

@LiamDonohue Ikyk, I just don’t want ppl scaring themselves with the term “AP”.

Highwayman (1443)

@LiamDonohue yeah lol. Some kids came into my class the other day to explain what AP English was like and literally the entire class was like nope no thank you

LiamDonohue (291)

btw we have a classroom now join with the link at the bottom of this post @Coder100

LiamDonohue (291)

if you don't mind, could you start working on the assignment? @Coder100

LiamDonohue (291)

its not graded just to see how much you understood @Coder100

Coder100 (17018)

Lol did it made a constant @LiamDonohue

Highwayman (1443)

@LiamDonohue :O Wat I wanna be in the classroom Imma join

Highwayman (1443)

@LiamDonohue you know! Lol. I did the first exam :P

Highwayman (1443)

@LiamDonohue XD. How do you get input that’s not a string? I can’t figure out how to get input that’s not a string. :(

Highwayman (1443)

@LiamDonohue well I know that I can do

string t = Console.ReadLine();

but I don’t know how to get a double, say, instead. This

double d = Console.ReadLine();

Of course throws an error. :/

LiamDonohue (291)

ohh ok uh i was going to do this later on, but the double variable has a special input syntax:

double = Double.Parse(Console.WriteLine);


Highwayman (1443)

@LiamDonohue oh. Oh ok. So. Ok yeah cool thnx!

Highwayman (1443)

Can I criticize your tutorial? Just some wording seems off...

LiamDonohue (291)

sure this is my first time @Highwayman

Highwayman (1443)

@LiamDonohue ok. So. First off, a string can hold spaces or returns or \b or all sorts of other things that are not alphanumeric. Same for char.
Integers are signed, they just can’t get decimal points. Doubles can. Otherwise it seems good. 👍 :)