Sarthak Jain (6th SEM) .Net - Practicle File
Sarthak Jain (6th SEM) .Net - Practicle File
class Program
{
static void Main()
{
Console.Write("Enter marks: ");
int marks = Convert.ToInt32(Console.ReadLine());
using System;
class Program {
static void Main(string[] args) {
foreach (string arg in args) {
Console.WriteLine("Argument: " + arg);
}
}
}
PRACTICAL : 3
class Program {
static void Main() {
Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
// if
if (num > 0) Console.WriteLine("Positive");
// switch
switch (num) {
case 10: Console.WriteLine("Ten"); break;
default: Console.WriteLine("Other"); break;
}
// conditional
string result = (num % 2 == 0) ? "Even" : "Odd";
Console.WriteLine(result);
} }
PRACTICAL : 5
class Program {
static void Main() {
// for loop
for (int i = 0; i < 3; i++) {
Console.WriteLine("For: " + i);
}
// while loop
int j = 0;
while (j < 3) {
Console.WriteLine("While: " + j);
j++;
}
// do-while loop
int k = 0;
do {
Console.WriteLine("Do-While: " + k);
k++;
} while (k < 3);
}
}
PRACTICAL: 6
class Program {
static void Main() {
string str = "hello";
char[] charArray = str.ToCharArray();
Array.Reverse(charArray);
Console.WriteLine("Reversed string: " + new string(charArray));
class Program {
static void Main() {
int[] arr = {1, 2, 3, 4, 5};
foreach (int val in arr) {
Console.WriteLine(val);
}
}
}
PRACTICAL: 8
class Program {
static void Main() {
int[] arr = {10, 20, 30, 40, 50};
int key = 30;
int index = Array.BinarySearch(arr, key);
Console.WriteLine(index >= 0 ? $"Found at index {index}" : "Not
found");
}
}
PRACTICAL: 9
class Program {
static void Main() {
int[] arr = {5, 1, 4, 2, 8};
for (int i = 0; i < arr.Length - 1; i++) {
for (int j = 0; j < arr.Length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
foreach (int val in arr) Console.Write(val + " ");
}
}
PRACTICAL: 10
class Program {
static void Main() {
int[] arr = {10, 20, 4, 45, 99};
int first = int.MinValue, second = int.MinValue;
class Program {
static void Main() {
int num = 123;
object obj = num; // Boxing
int unboxed = (int)obj; // Unboxing
class Person {
public string Name;
public void SayHello() {
Console.WriteLine("Hello, " + Name);
}
}
class Program {
static void Main() {
Person p = new Person();
p.Name = "Aditya";
p.SayHello();
}
}