Simple C# programs
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sudarshan HajareRank #741 · 3.1K reputationPosted Jun 19, 2026, 8:38 PM EDT
Here are simple c# programs
Hello World
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Add Two Numbers
using System;
class Program
{
static void Main()
{
int a = 10;
int b = 20;
int sum = a + b;
Console.WriteLine("Sum = " + sum);
}
}
Find Even or Odd Number
using System;
class Program
{
static void Main()
{
int num = 7;
if (num % 2 == 0)
Console.WriteLine("Even");
else
Console.WriteLine("Odd");
}
}
Swap Two Numbers
using System;
class Program
{
static void Main()
{
int a = 5, b = 10;
int temp = a;
a = b;
b = temp;
Console.WriteLine("a = " + a);
Console.WriteLine("b = " + b);
}
}
Find Largest of Three Numbers
using System;
class Program
{
static void Main()
{
int a = 10, b = 25, c = 15;
int largest = a;
if (b > largest)
largest = b;
if (c > largest)
largest = c;
Console.WriteLine("Largest = " + largest);
}
}