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.
Disclaimer!
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.
Setup
For NOW use repl.it but later I'd recommend using a real IDE and or compiler.
Overview of a basic C# file.
using System;
class MainClass {
public static void Main (string[] args) {
<code>
}
}
Let's break down the file.
using System;? Well that is kind of like a #include or import statement. It's how we include new commands in our program.
The 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, speed, brand, model, ect.
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 value.
Does that make sense?
Anyway public static void Main (string[] args) wow that is a mouthfull.
This is an example of a method!
The public is an identifier saying who can access this variable. See private.
The static means that the value of this method can never change.
The 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.
The (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!
Make sense?
Hello, World!
Okay finally, results!
So printing to the console is as easy as this:
Console.WriteLine("Hello, World!");
Notice that most lines in C# end with a semicolon or a bracket.
Also C# is cAsE seNsiTivE so remember that.
The Console is a class in the System library that we imported using using System;.
And WriteLine is a method of Console.
This method takes a string type as an argument. We will go in depth on data types in the next section.
Variables
In this section we will discuss Variables and Data Types in C#
Data Types
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 a, b, c, ect. Surrounded by 's
A method with the attribute DllImportAttribute is declared.
Okay so yeah they are kinda difficult.
Inheritance
Take this example from the Microsoft Documentation:
using System;
public class A
{
private int value = 10;
public class B : A
{
public int GetValue()
{
return this.value;
}
}
}
public class C : A
{
// public int GetValue()
// {
// return this.value;
// }
}
public class Example
{
public static void Main(string[] args)
{
var b = new A.B();
Console.WriteLine(b.GetValue());
}
}
// The example displays the following output:
// 10
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.
C# FULL Beginners Crash Course
C# Full Beginners Crash Course
Hello fellow replitors.
This course is dedicated to me.
Anyway.
Let's get started.
Table of contents
Introduction
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.
Disclaimer!
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.
Setup
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#include
orimport
statement. It's how we include new commands in our program.The
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,
speed
,brand
,model
, ect.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 calledvalue
.Does that make sense?
Anyway
public static void Main (string[] args)
wow that is a mouthfull.This is an example of a method!
The
public
is an identifier saying who can access this variable. Seeprivate
.The
static
means that the value of this method can never change.The
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.The
(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!
Make sense?
Hello, World!
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.
The
Console
is a class in theSystem
library that we imported usingusing System;
.And
WriteLine
is a method ofConsole
.This method takes a
string
type as an argument. We will go in depth on data types in the next section.Variables
In this section we will discuss Variables and Data Types in C#
Data Types
a
,b
,c
, ect. Surrounded by 'schar
typesabc
,def
,ghi
, ect. Surrounded by "sDeclaring Variables without giving them an immidiate value.
Consider the code below
The syntax is
<type> <name>;
.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.
Float
We put an
f
at the end because the value defaults to adouble
type.Double
Char
We put 's around the value to indicate that we are using a char type.
String
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
Hello, World!
.They have methods and attributes.
Terminology
We will review how to make classes, methods, ect. in the section
In-Depth OOP
.Input
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.
Functions
Okay, functions or methods are really easy.
Identifiers
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.
Access Modifiers
Other Modifiers
Syntax
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
protected
orabstract
.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:
<type> <name>
They are function-scope variables.
The code in the function must be in brackets.
IF statement.
Logic, finally.
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:
Operators
!=
- Does not equal==
- equals>=
or=>
- greater than or equal to<=
or=<
- less than or equal to.>
- greater than<
- less than&&
- and||
- orElse 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:
Syntax:
WHILE Loop
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.
FOR Loop
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.
Interesting Features
C# .NET comes with many different features.
Let's Look at a few.
Beep.
It makes a beeping sound. Doesn't work on repl.it.
Yep.
<value>++;
OR
It increments the value by 1.
In-Depth OOP
Okay this section is going to be really big. Just kiding I'm going to make it as quick and simple as possible
Classes
I hope at this point you understand what a class is.
Syntax
The modifiers are the same as in
functions
section.Methods.
Okay.
Attributes
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.
Inheritance
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.
Conclusion
Well. Upvote, feedback.
Bibliography
Works Cited
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/.
Oo Swift! I’ve been looking at it, and it’s a very interesting language idea at least... @Wuru