Learn C# from Scratch
Hello! Welcome
Today we are going to learn C# from scratch.
What is C#?
C# (pronounced “C Sharp”) is a modern programming language created by Microsoft.
It is used to develop games, desktop applications, websites
It is used to create all kinds of applications!
Installing the environment
To get started with C#, you need to install Visual Studio, the recommended development environment (IDE).
There is a Community version that is free for personal use.
Visit the official Visual Studio page.
Write your first code
Now you can create a new console project and write the following:
Console.WriteLine("Hello, LuisLlamas.es!");
You now have your first program in C#, the classic “Hello, World”.
Compile and run
Once you write your code, compile the program in Visual Studio and run it to see the results.
C# will handle translating your code to something the computer understands. Congratulations! Wasn’t that easy?
You’re doing great!
Now let’s talk about the syntax of C#.
Variables
Variables in C# allow you to store information like numbers, text, or boolean values (true/false).
int value = 10;
int sum = value + 5;
With C# you can perform mathematical operations like addition, subtraction, multiplication, and division. Perfect for simple and complex calculations!
Conditionals
Conditionals in C# allow you to make decisions. Using if you can make the program act one way or another depending on the conditions.
int number = 5;
if (number > 0) {
Console.WriteLine("The number is positive.");
}
Loops
Loops allow you to repeat actions. With for, while, or foreach, you can make C# repeat a task multiple times.
for (int i = 1; i <= 5; i++) {
Console.WriteLine(i);
}
Methods
Methods are blocks of code that perform a specific task. They allow you to organize and reuse your code.
public int Add(int a, int b) {
return a + b;
}
You’re almost there!
We just need to see how to structure your code.
Classes and objects
C# is an object-oriented language. This means you can create classes that represent real-world objects, like a car or an animal, and manipulate their properties.
There are also other data structures like structs, tuples, or records.
Arrays and collections
In C#, you can use collections like arrays, lists, or dictionaries to store groups of data. For example, a list of numbers or a list of names.
LINQ (Language Integrated Query) allows you to query data collections in a simple and readable way.
What is a library?
Libraries are collections of code that we keep together to make them easier to reuse.
They allow us to save time and effort by not having to write everything from scratch.
NuGet is the package manager for .NET. It allows us to easily download and install free and public libraries in our projects. :::
Well done!
You now have the basics of C#! Keep practicing to become an expert.