KEMBAR78
Beginner DotNet Programs | PDF
0% found this document useful (0 votes)
9 views6 pages

Beginner DotNet Programs

This document contains 20 beginner C#/.NET programs that demonstrate fundamental programming concepts. Examples include printing 'Hello, World!', performing arithmetic operations, using control structures like if-else and loops, and handling user input. Each program is presented with its source code for easy understanding and learning.

Uploaded by

padmahyd2405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Beginner DotNet Programs

This document contains 20 beginner C#/.NET programs that demonstrate fundamental programming concepts. Examples include printing 'Hello, World!', performing arithmetic operations, using control structures like if-else and loops, and handling user input. Each program is presented with its source code for easy understanding and learning.

Uploaded by

padmahyd2405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

20 Beginner C#/.

NET Programs

1. Hello World
using System;

class Program {
static void Main(string[] args) {
Console.WriteLine("Hello, World!");
}
}

2. Add Two Numbers


using System;

class Program {
static void Main(string[] args) {
int a = 5, b = 3;
int sum = a + b;
Console.WriteLine("Sum: " + sum);
}
}

3. If-Else Example
using System;

class Program {
static void Main(string[] args) {
int num = 10;
if (num > 0)
Console.WriteLine("Positive");
else
Console.WriteLine("Non-positive");
}
}

4. For Loop Example


using System;

class Program {
static void Main(string[] args) {
for (int i = 1; i <= 5; i++)
Console.WriteLine("Number: " + i);
}
}

5. While Loop Example


using System;

class Program {
static void Main(string[] args) {
int i = 1;
while (i <= 5) {
Console.WriteLine("Count: " + i);
i++;
}
}
}

6. String Concatenation
using System;

class Program {
static void Main(string[] args) {
string first = "Hello";
string second = "World";
Console.WriteLine(first + " " + second);
}
}

7. Array Example
using System;

class Program {
static void Main(string[] args) {
int[] numbers = { 1, 2, 3, 4, 5 };
foreach (int num in numbers)
Console.WriteLine(num);
}
}

8. Switch Case
using System;

class Program {
static void Main(string[] args) {
int day = 3;
switch (day) {
case 1: Console.WriteLine("Monday"); break;
case 2: Console.WriteLine("Tuesday"); break;
case 3: Console.WriteLine("Wednesday"); break;
default: Console.WriteLine("Other day"); break;
}
}
}

9. Function Example
using System;

class Program {
static void Greet(string name) {
Console.WriteLine("Hello " + name);
}

static void Main(string[] args) {


Greet("Padma");
}
}

10. Read Input


using System;

class Program {
static void Main(string[] args) {
Console.Write("Enter name: ");
string name = Console.ReadLine();
Console.WriteLine("Hi " + name);
}
}

You might also like