C# FULL Beginners Crash Course
C# Full Beginners Crash Course
Hello fellow replitors.
This course is dedicated to me.
Let's get started.
Table of contents
- Overview of a basic C# file
- Hello, World!
- Basic OOP Overview
- IF Statement
- WHILE Loop
- FOR Loop
- Interesting Features
- In-Depth OOP
- Where to go from here
C# is an Object-Oriented, strongly typed, and overall great language developed by Microsoft in 2000.
It is kind of a Java-Wannabe.
In terms of this it wants to be cross-platform but barely.
It works great on windows but not so well on other platforms.
Today we will be focusing on the cross-platform side of C#
It is still a great language though.
This course is accelerated so I will not be going in depth in many topics, for instance what an array is. Mainly this tutorial will be HOWs and all WHYs will mainly be about best practices and not metaphors.
This course is aimed at people with a Python, Java, C, or C++ background.
If you know HTML, CSS, JS, TS, Ruby, or anything else you can still learn but it may be slightly harder.
The course will NOT teach you an IDE you can use repl.it or learn an IDE but I am not here to teach you an IDE.
But without further ado let's get a move on.
For NOW use repl.it but later I'd recommend using a real IDE and or compiler.
Overview of a basic C# file.
Let's break down the file.
using System;? Well that is kind of like a
import statement. It's how we include new commands in our program.
MainClass class is well, a class.
If you have no idea what a class is here is a basic overview.
Think about you driving a car the car has attributes,
This car also has methods like starting it up, moving it, ect.
So, this is kind of like a class.
The class has methods and attributes,
Kind of like a data type.
The data type int might have a method called
makeNegative() and an attribute called
Does that make sense?
public static void Main (string args) wow that is a mouthfull.
This is an example of a method!
public is an identifier saying who can access this variable. See
static means that the value of this method can never change.
void means that this method returns nothing.
Main is the name. You must have a main class in your program for it to run and compile.
(string args) is hard to explain if you don't come from a Java background.
When the user runs the program, they can specify args: myprogram.exe arg1 arg2.
And it turns them into a string array.
So you can reference them in your function!
Okay finally, results!
So printing to the console is as easy as this:
Notice that most lines in C# end with a semicolon or a bracket.
Also C# is cAsE seNsiTivE so remember that.
Console is a class in the
System library that we imported using
WriteLine is a method of
This method takes a
string type as an argument. We will go in depth on data types in the next section.
In this section we will discuss Variables and Data Types in C#
- int , a 32-bit signed integer
- float , a 32-bit signed floating point value.
- long , a 64-bit signed integer
- double , a 64-bit signed number (decimal or not)
- byte , a 8-bit signed integer
- bool , a True, False value (1 byte)
- char , a single unicode character
c, ect. Surrounded by 's
- string , multiple
ghi, ect. Surrounded by "s
Declaring Variables without giving them an immidiate value.
Consider the code below
The syntax is
Declaring & Assigning a variable.
The syntax is
<type> <name> = <value>;.
Examples of various variable assignments
Some types in C# have special ways to assign them.
Lets review these.
We put an
f at the end because the value defaults to a
We put 's around the value to indicate that we are using a char type.
We put "s around the value to indicate that we are using a string type.
That's about it for basic variables.
Basic OOP Overview.
OOP or Object Oriented Programming is the fork of programming revolving around classes and such.
If you do Java or C++ this is probably engraved into your mind anyway.
We discussed Classes a bit in the section
They have methods and attributes.
- Member - (Methods & Attributes)
- Instance - A object using that class
- Method - a function in that class
- Attribute - a sort of identifier but not really.
We will review how to make classes, methods, ect. in the section
Short section but still important.
So to read a line we can do.
And this will return a value of type string that is the input.
So we can do.
To read a single key without the user having to press enter afterword we can do:
And it returns a char.
Okay, functions or methods are really easy.
Identifiers are things that can tell the compiler who can access this class/method, if it can ever change, ect.
Let's go over a few.
- public - everyone can access this.
- private - can only be accessed in the class itself
- internal - can only be accessed in the current project assembly.
- protected - can only be accessed within the class or any classes that inherit from the class
- static - only instanciated once and never reinstated.
- abstract - tells the compiler that the object being changed has a missing or incomplete implementation.
- virtual - used to change a method, property, indexer, or event declaration and allow for it to be overridden in a derived class.
- const - used with variables to declare that its value can never change
Consider the example below:
The syntax is
<modifiers> <return_type> <name> (<args>)
Darn that is a headache, let's break this down.
The modifiers are things like
The return type is what the function returns (data type).
The return type in the example above is
void that means that the function returns nothing.
The name is a way to reference the function.
The args have their own syntax:
They are function-scope variables.
The code in the function must be in brackets.
Okay so if you are not familiar with an if statement, then learn more of your best language then come back here.
But we can show you syntax here:
!=- Does not equal
=>- greater than or equal to
=<- less than or equal to.
>- greater than
<- less than
Else if and Else
Else if has the same syntax as if, it executes if the prior if and or else if statements weren't executed but this condition is true.
Else statements executes if the prior if and else if statements werent true:
As much as I despise the WHILE Loop and encourage the FOR Loop most people love the WHILE Loop.
So I need to cover it.
The syntax is:
And the same operators can be used in the WHILE Loop as well as in the IF statement.
That is pretty much it, haha.
Statement 1 runs one time before the execution of the code.
Statement 2 defines the condition for executing the code.
Statement 3 runs every time after the code is executed.
C# .NET comes with many different features.
Let's Look at a few.
It makes a beeping sound. Doesn't work on repl.it.
It increments the value by 1.
Okay this section is going to be really big. Just kiding I'm going to make it as quick and simple as possible
I hope at this point you understand what a class is.
The modifiers are the same as in
As defined in
Basic OOP Overview. these are kind of like indentifiers except not.
They are a whole other fork and I won't really show you how to make them but I want you to know what they are.
But I'll show you an example from the Microsoft Documentation:
A method with the attribute DllImportAttribute is declared.
Okay so yeah they are kinda difficult.
Take this example from the Microsoft Documentation:
Inheritance is the act of one class inheriting from another.
Again a very in-depth field.
Where to go from here.
I'd suggest making a few programs and checking out the Microsoft Documentation.
C# is a very expansive language. And there is so much you can do with it.
There are so many jobs in C#
But if you wanted to learn more from me comment down below that you want to see an Intermediate Course.
Well. Upvote, feedback.
BillWagner. “C# Docs - Get Started, Tutorials, Reference.” Microsoft.Com, 2019, docs.microsoft.com/en-us/dotnet/csharp/.
“C# Tutorial - Tutorialspoint.” Www.Tutorialspoint.Com, www.tutorialspoint.com/csharp/index.htm.
“C# Tutorial (C Sharp).” W3schools.Com, 2019, www.w3schools.com/cs/.
Not really in depth. you just wrote n++ ++n you didn't even talk about incrementing after or before.
@Highwayman .NET has a bunch of built-in functions and stuff that speeds up the development process by a grand magnitude. The problem is, some functionality that other languages would call essential is locked in .NET, such as JSON, modern web requests, and GUI (although I doubt Repl.it would implement WPF because of a lower demand). Sure, you could code that all by hand, and sure there are older libraries for some of those things, but either way there's still a lot of functionality we're missing without the .NET core.
Good. as a note that you could add to the tutorial. C# exists because Java could be used on any OS which Microsoft did not like. So they made C# os dependent on what Windows ran on for the most part. And it just so happened that they had the same syntax and semantic styling.