C# is a multi-paradigm programming language developed by Microsoft. It is widely used for building Windows applications, web applications, and games using the .NET framework.
Here's a basic "Hello, World!" program in C#:
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
C# supports variables and operations similarly to other languages:
using System;
class Program
{
static void Main()
{
int a = 10;
int b = 5;
int sum = a + b;
int product = a * b;
Console.WriteLine($"Sum: {sum}");
Console.WriteLine($"Product: {product}");
}
}
Using conditional statements in C#:
using System;
class Program
{
static void Main()
{
int number = 10;
if (number > 0)
{
Console.WriteLine("The number is positive.");
}
else
{
Console.WriteLine("The number is not positive.");
}
}
}
Example of a loop in C#:
using System;
class Program
{
static void Main()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine($"Number: {i}");
}
}
}