Beginner Level .
NET (C#) Programs
1. Hello World
using System;
class Program
static void Main()
[Link]("Hello World");
2. Addition of two numbers
using System;
class Program
static void Main()
int a = 10, b = 20;
int sum = a + b;
[Link]("Sum = " + sum);
3. Even or Odd
using System;
class Program
static void Main()
int num = 7;
if (num % 2 == 0)
[Link]("Even");
else
[Link]("Odd");
4. Largest of three numbers
using System;
class Program
static void Main()
int a = 10, b = 20, c = 15;
if (a > b && a > c)
[Link]("A is largest");
else if (b > c)
[Link]("B is largest");
else
[Link]("C is largest");
5. Factorial
using System;
class Program
static void Main()
int num = 5, fact = 1;
for(int i=1;i<=num;i++)
fact *= i;
[Link]("Factorial = " + fact);
Intermediate Level Programs
6. Reverse a number
using System;
class Program
static void Main()
int num = 1234, rev = 0;
while(num > 0)
int rem = num % 10;
rev = rev * 10 + rem;
num /= 10;
[Link]("Reverse = " + rev);
7. Palindrome number
using System;
class Program
{
static void Main()
int num = 121, temp = num, rev = 0;
while(temp > 0)
rev = rev * 10 + temp % 10;
temp /= 10;
if(num == rev)
[Link]("Palindrome");
else
[Link]("Not Palindrome");
8. Fibonacci series
using System;
class Program
static void Main()
int a = 0, b = 1;
for(int i=0;i<10;i++)
[Link](a + " ");
int c = a + b;
a = b;
b = c;
}
9. Array sorting
using System;
class Program
static void Main()
int[] arr = {5,3,8,1};
[Link](arr);
foreach(int num in arr)
[Link](num + " ");
10. Find largest in array
using System;
class Program
static void Main()
int[] arr = {10, 50, 30, 20};
int max = arr[0];
foreach(int num in arr)
if(num > max)
max = num;
[Link]("Max = " + max);
OOP Programs (Very Important for Interviews)
11. Class and Object
using System;
class Student
public string name;
public void display()
[Link]("Name: " + name);
class Program
static void Main()
Student s = new Student();
[Link] = "Nitya";
[Link]();
12. Constructor
class Student
public Student()
[Link]("Constructor called");
13. Inheritance
class Animal
public void eat()
[Link]("Eating");
class Dog : Animal
public void bark()
[Link]("Barking");
14. Polymorphism (Method Overloading)
class Math
public int add(int a, int b)
return a + b;
}
public int add(int a, int b, int c)
return a + b + c;
15. Encapsulation
class Person
private string name;
public string Name
get { return name; }
set { name = value; }
Advanced .NET Programs
16. Exception Handling
using System;
class Program
static void Main()
try
int a = 10, b = 0;
int c = a / b;
}
catch(Exception e)
[Link]("Error: " + [Link]);
17. File Handling
using System;
using [Link];
class Program
static void Main()
[Link]("[Link]", "Hello Nitya");
string text = [Link]("[Link]");
[Link](text);
18. LINQ Example
using System;
using [Link];
class Program
static void Main()
int[] numbers = {1,2,3,4,5};
var result = [Link](n => n > 3);
foreach(var num in result)
[Link](num);
Database Program ([Link])
using [Link];
SqlConnection con = new SqlConnection("connection string");
[Link]();
[Link]("Connected");
[Link]();
MOST IMPORTANT PROGRAMS FOR INTERVIEW (Must Practice)
Practice these first:
1. Factorial
2. Palindrome
3. Fibonacci
4. Array sorting
5. Reverse number
6. Largest number
7. Class & Object
8. Inheritance
9. Exception handling
10. Database connection
If you want, I will prepare for you:
✔ Top 30 .NET interview programs
✔ With output
✔ With explanation
✔ Interview questions
Just say: "Yes, prepare top 30 .NET programs for interview"
top 30
Here are the Top 30 .NET (C#) Programs for Interview (Beginner → Advanced). These are most
frequently asked in interviews for .NET Developer roles using C# and .NET by Microsoft.
Beginner Level (1–10)
1. Hello World
[Link]("Hello World");
2. Swap two numbers
int a = 10, b = 20;
int temp = a;
a = b;
b = temp;
[Link](a + " " + b);
3. Even or Odd
int num = 7;
[Link](num % 2 == 0 ? "Even" : "Odd");
4. Positive, Negative, or Zero
int num = -5;
if(num > 0) [Link]("Positive");
else if(num < 0) [Link]("Negative");
else [Link]("Zero");
5. Largest of three numbers
int a=10,b=20,c=15;
int max = [Link](a, [Link](b,c));
[Link](max);
6. Factorial
int fact=1, num=5;
for(int i=1;i<=num;i++)
fact*=i;
[Link](fact);
7. Multiplication table
int num=5;
for(int i=1;i<=10;i++)
[Link](num+" x "+i+" = "+(num*i));
8. Sum of digits
int num=123, sum=0;
while(num>0)
sum+=num%10;
num/=10;
[Link](sum);
9. Reverse number
int num=123, rev=0;
while(num>0)
rev=rev*10+num%10;
num/=10;
[Link](rev);
10. Palindrome number
int num=121, temp=num, rev=0;
while(temp>0)
rev=rev*10+temp%10;
temp/=10;
[Link](num==rev?"Palindrome":"Not Palindrome");
Intermediate Level (11–20)
11. Fibonacci series
int a=0,b=1,c;
for(int i=0;i<10;i++)
[Link](a+" ");
c=a+b;
a=b;
b=c;
12. Prime number
int num=7;
bool prime=true;
for(int i=2;i<=num/2;i++)
if(num%i==0)
prime=false;
break;
}
}
[Link](prime?"Prime":"Not Prime");
13. Count digits
int num=12345,count=0;
while(num>0)
count++;
num/=10;
[Link](count);
14. Armstrong number
int num=153,temp=num,sum=0;
while(temp>0)
int rem=temp%10;
sum+=rem*rem*rem;
temp/=10;
[Link](sum==num?"Armstrong":"Not Armstrong");
15. Array sorting
int[] arr={5,3,8,1};
[Link](arr);
foreach(int i in arr)
[Link](i+" ");
16. Largest element in array
int[] arr={10,20,50,30};
int max=arr[0];
foreach(int i in arr)
if(i>max) max=i;
[Link](max);
17. Reverse array
int[] arr={1,2,3,4};
[Link](arr);
foreach(int i in arr)
[Link](i+" ");
18. Find duplicate elements
int[] arr={1,2,3,2,4,1};
for(int i=0;i<[Link];i++)
for(int j=i+1;j<[Link];j++)
if(arr[i]==arr[j])
[Link](arr[i]);
19. String reverse
string str="hello";
char[] ch=[Link]();
[Link](ch);
[Link](new string(ch));
20. Count vowels
string str="hello";
int count=0;
foreach(char c in str)
if("aeiou".Contains(c))
count++;
[Link](count);
OOP Programs (21–25)
21. Class and object
class Student
public string name="Nitya";
Student s=new Student();
[Link]([Link]);
22. Constructor
class Test
public Test()
[Link]("Constructor called");
new Test();
23. Inheritance
class A
public void show(){[Link]("Base");}
class B:A{}
B obj=new B();
[Link]();
24. Method Overloading
class Test
{
public int add(int a,int b){return a+b;}
public int add(int a,int b,int c){return a+b+c;}
25. Method Overriding
class A
public virtual void show(){[Link]("Base");}
class B:A
public override void show(){[Link]("Derived");}
Advanced Level (26–30)
26. Exception handling
try
int a=10,b=0;
[Link](a/b);
catch(Exception e)
[Link]([Link]);
27. File handling
[Link]("[Link]","Hello");
[Link]([Link]("[Link]"));
28. LINQ example
int[] arr={1,2,3,4,5};
var result=[Link](x=>x>3);
foreach(var i in result)
[Link](i);
29. Database connection ([Link])
SqlConnection con=new SqlConnection("connection string");
[Link]();
[Link]("Connected");
[Link]();
30. Generic class
class Test<T>
public T data;
Test<int> obj=new Test<int>();
[Link]=10;
[Link]([Link]);
MOST IMPORTANT (Focus first for interview)
Priority order:
1. Palindrome
2. Fibonacci
3. Prime number
4. Factorial
5. Array sorting
6. String reverse
7. OOP concepts
8. Exception handling
9. File handling
10. Database connection
If you want, I can also give Top 30 .NET interview questions with answers (HR + technical) which are
asked in companies like TCS, Infosys, and Wipro.