Chapter 1: Introduction to C#
C# is a programming language that helps us create computer programs and applications. It is a powerful language used by many professional developers. In this chapter, we will learn the basics of C# and how to get started with writing our first program.
Lesson 1: Setting Up
To write C# programs, we need to have an integrated development environment (IDE). An IDE is a software that helps us write, test, and run our code. One popular IDE for C# is Visual Studio, which you can download and install for free.
Lesson 2: Hello, World!
In the world of programming, it is a tradition to start with a simple program that prints "Hello, World!" on the screen. Let's write our first C# program together:
csharp
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Here's what each line of the program does:
The using System; line tells the computer that we want to use some pre-built features from the "System" library.
The class Program line defines a class called "Program" which is the container for our code.
The static void Main() line is the entry point of our program. It's where the program starts running.
The Console.WriteLine("Hello, World!"); line prints the text "Hello, World!" on the screen.
To run this program, save it with a .cs extension (e.g., HelloWorld.cs), open it in Visual Studio, and click on the "Start" button or press F5. You should see the output "Hello, World!" displayed in the output window.
Chapter 2: Variables and Data Types
In this chapter, we will learn about variables and data types in C#. Variables are like containers that hold different types of data. Data types define the kind of data a variable can store.
Lesson 1: Declaring Variables
To declare a variable in C#, we need to specify its data type and give it a name. Here's an example:
csharp
int age;
In this example, we declare a variable called "age" of type int, which stands for integer. An integer is a whole number without any decimal places.
Lesson 2: Assigning Values to Variables
After declaring a variable, we can assign a value to it using the assignment operator =. Here's an example: