Learn Technology in Simple English
C# (pronounced "C Sharp") is a modern programming language developed by Microsoft. It is commonly used to build applications, web services, games, desktop software and other types of software.
C# is closely associated with the .NET platform, which provides tools and libraries developers can use to build applications.
C# was developed at Microsoft during the late 1990s and was first released in the early 2000s.
It was designed as a modern programming language for Microsoft's software development ecosystem.
C# has continued to evolve with new language features and improvements.
C# is used across several areas of software development.
.NET is a software development platform from Microsoft. It provides runtimes, libraries, development tools and other technologies that can be used to build applications.
C# is one of the main programming languages used with .NET.
Developers can use .NET to create applications for different operating systems and platforms.
A developer writes C# source code. The code is then compiled and executed using the .NET environment.
The compiler checks the code and converts it into an intermediate form that can be executed by the .NET runtime.
This process allows developers to build applications while benefiting from features provided by the .NET platform.
A simple C# program can display a message on the screen.
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Console.WriteLine() is used to display text in the console.
Variables store information that a program can use.
string name = "Ali";
int age = 25;
double price = 150.50;
bool active = true; Each variable has a data type that describes the kind of value it stores.
| Type | Example | Purpose |
|---|---|---|
| string | "Hello" | Text |
| int | 25 | Whole numbers |
| double | 25.5 | Decimal numbers |
| float | 10.5f | Decimal numbers |
| decimal | 100.50m | Precise decimal values |
| bool | true | True or false |
| char | 'A' | Single character |
C# also allows developers to use var when the compiler can
determine the variable's type from its value.
var name = "Ali";
var age = 25;
The type still exists; var simply allows the compiler to
infer it from the assigned value.
Strings are used to store text.
string name = "Abdullahi";
Console.WriteLine(name); C# also supports string interpolation.
string name = "Abdullahi";
int age = 25;
Console.WriteLine($"My name is {name} and I am {age} years old.");Operators are used to perform calculations and comparisons.
int a = 10;
int b = 5;
Console.WriteLine(a + b);
Console.WriteLine(a - b);
Console.WriteLine(a * b);
Console.WriteLine(a / b);
C# also has comparison operators such as ==,
!=, >, <,
>= and <=.
Conditional statements allow programs to make decisions.
int age = 20;
if (age >= 18)
{
Console.WriteLine("Adult");
}
else
{
Console.WriteLine("Not an adult");
}A switch statement can be useful when a program needs to choose between several possible values.
int day = 2;
switch (day)
{
case 1:
Console.WriteLine("Monday");
break;
case 2:
Console.WriteLine("Tuesday");
break;
default:
Console.WriteLine("Other day");
break;
}Loops repeat instructions.
for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i);
}int i = 1;
while (i <= 5)
{
Console.WriteLine(i);
i++;
}In C#, methods are reusable blocks of code that perform tasks.
static void Greet()
{
Console.WriteLine("Hello!");
} A method can receive parameters.
static void Greet(string name)
{
Console.WriteLine($"Hello {name}");
}A method can return a value to the code that called it.
static int Add(int a, int b)
{
return a + b;
}
int result = Add(5, 3);
Console.WriteLine(result);Arrays store multiple values of the same type.
string[] names = {
"Ali",
"Umar",
"Aisha"
};
Console.WriteLine(names[0]);
C# provides collections such as List<T> for storing
groups of values.
using System.Collections.Generic;
List<string> names = new List<string>();
names.Add("Ali");
names.Add("Umar");
names.Add("Aisha");
Console.WriteLine(names[0]);C# is an object-oriented programming language. A class can act as a blueprint for objects.
class Person
{
public string Name;
public int Age;
}
class Program
{
static void Main()
{
Person person = new Person();
person.Name = "Ali";
person.Age = 25;
Console.WriteLine(person.Name);
}
}Object-oriented programming, often called OOP, is an important part of C#.
Common OOP concepts include:
Inheritance allows one class to derive functionality from another class.
class Animal
{
public void Eat()
{
Console.WriteLine("Eating");
}
}
class Dog : Animal
{
public void Bark()
{
Console.WriteLine("Barking");
}
}An interface defines members that a class can implement.
interface IAnimal
{
void Speak();
}
class Dog : IAnimal
{
public void Speak()
{
Console.WriteLine("Woof");
}
}
Programs sometimes encounter errors while running.
C# provides exception handling using try,
catch and related keywords.
try
{
int number = int.Parse("abc");
}
catch
{
Console.WriteLine("An error occurred.");
}C# can be used for web development through the .NET ecosystem.
Developers can build websites, web applications, APIs and backend systems using technologies such as ASP.NET Core.
C# can be used to create APIs and applications that communicate with APIs over the Internet.
For example, a C# application can request information from a server, receive JSON data and process that information.
C# applications can communicate with databases to store and retrieve information.
A business application might use a database to store:
C# is widely associated with game development, especially through the Unity game engine.
Developers can use C# scripts to control game objects, player movement, game logic, user interfaces and many other game features.
C# can be used to create desktop applications for supported platforms.
Examples include business tools, management software, utilities and productivity applications.
C# and .NET can also be used to create cloud-based applications and backend services.
Cloud applications can process data, provide APIs, communicate with databases and serve users over the Internet.
| Feature | C# | C++ |
|---|---|---|
| Common ecosystem | .NET | Native/C++ ecosystem |
| Memory management | Mostly managed by runtime | More direct control available |
| Game development | Common with Unity | Common in performance-intensive engines |
| Web development | Strong .NET support | Less commonly used for modern web backends |
| Feature | C# | Java |
|---|---|---|
| Main ecosystem | .NET | JVM ecosystem |
| Web development | ASP.NET Core | Many Java frameworks |
| Game development | Common with Unity | Less common for mainstream game engines |
| Cross-platform development | Supported through modern .NET | Strong JVM support |
C# has many features, so beginners should learn it gradually.
// Variable
string name = "Ali";
int age = 25;
// Output
Console.WriteLine("Hello");
// If
if (age >= 18)
{
Console.WriteLine("Adult");
}
// Method
static int Add(int a, int b)
{
return a + b;
}
// Array
int[] numbers = { 1, 2, 3 };
// For loop
for (int i = 0; i < 3; i++)
{
Console.WriteLine(numbers[i]);
}Yes. C# is a general-purpose programming language developed by Microsoft.
C# is used for web applications, APIs, desktop software, games, business applications and other software.
Yes. C# is widely used with the Unity game engine.
No. C# and C++ are different programming languages with different ecosystems and design goals.
Beginners can learn C# step by step. It has many features, so regular practice is important.
.NET is a development platform that provides tools, libraries and a runtime for building applications.
Yes. C# can be used for web development and backend services through technologies such as ASP.NET Core.
Yes. C# applications can connect to databases and read or write data.
C# is a powerful and widely used programming language that can be used for many types of software development.
Its connection with the .NET platform makes it useful for web development, APIs, desktop applications, cloud services and business software.
C# is also an important language in game development, particularly when working with Unity.
If you are learning programming, start with the fundamentals and build small projects before moving into larger applications.