0% found this document useful (0 votes)
3 views

C#netBpart (1) (1)

The document outlines a C# .NET lab program consisting of multiple tasks, including creating console applications to demonstrate window controls, subroutines, and functions. It also includes exercises for filtering candidates based on height, segregating student register numbers by course and semester, performing mathematical operations using delegates, and demonstrating garbage collection activities. Each task is accompanied by code snippets and expected outputs.

Uploaded by

loginshiv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

C#netBpart (1) (1)

The document outlines a C# .NET lab program consisting of multiple tasks, including creating console applications to demonstrate window controls, subroutines, and functions. It also includes exercises for filtering candidates based on height, segregating student register numbers by course and semester, performing mathematical operations using delegates, and demonstrating garbage collection activities. Each task is accompanied by code snippets and expected outputs.

Uploaded by

loginshiv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

III SEM C# .

NET LAB SHW ETHA Y K

PART B

1. C#.NET console application to demonstrate window controls.

Program.cs File

using System;
using System.Windows.Forms;
using System. Drawing;

namespace ConsoleApplication16

class Program

static void Main(string[] args)

Application.Run(new Form1());

Form1.cs File:
using System;
using System.Collections;
using System. Data;
using System.Windows.Forms;

namespace ConsoleApplication16

public partial class Form1 : Form

public Form1()

InitializeComponent();

Dept Of BCA, SRNMN College Of Applied Sciences, 1


III SEM C# .NET LAB SHW ETHA Y K

private void Form1 Load(object sender, EventArgs e)

private void LabeI1 Click(object sender, EventArgs e)

OUTPUT:

HI AM CREATED BY CONSOLE APPLICATION

2. Demonstrate subroutines and functions I C#.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace subroutine

class Program

static void Main(string[] args)

Dept Of BCA, SRNMN College Of Applied Sciences, 2


III SEM C# .NET LAB SHW ETHA Y K

int result =
Add(25,25);
DispIayResuIts(result);
Console.ReadLine();

//this is a Function (returns a value)


static int Add(int number1, int number2)

return (number1 + number2);

//this is Subroutine (perform a task but dont return anything)


static void DispIayResuIts(int results)

Console.WriteLine(results);

50
OUTPUT:

3. Assume that 10 candidates have participated in an army selection drive. In


the first round of selection, candidates are shortlisted based on their height.
Minimum height for theseIectionis157.5 cms. Read the height of those 10
candidates in centimetres and list the heights which are equal to or more than
the minimum height required for the selection. Also count the number of
candidates who have been shortlisted like this. (Program can be written with or
without the array).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace heightofcandidate

Dept Of BCA, SRNMN College Of Applied Sciences, 3


III SEM C# .NET LAB SHW ETHA Y K

class Program3

public static void Main()

Console.Write("Enter no of ");
int n = int.Parse(Console.ReadLine());
double[] height = new double[n];
string[] name = new string[n];
Console.WriteLine("Enter (0} Candidates Name and Height:", n);
for (int i = 0; i < height.Length; i++)

name[i] = Console.ReadLine();
height[i] = double.Parse(Console.ReadLine());

Console.WriteLine("Shortlisted Candidates Height: ");


Console.WriteLine("Name\tHeight");
int cnt = 0;
for (int i = 0; i < height.Length; i++)

if (height[i] >= 157.5)

Console.Write(name[i] + "\t");
Console.WriteLine(height[i]);
cnt++,"

Console.WriteLine("Total no of candidates selected {0}", cnt);


Console.ReadLine();

OUTPUT:

Dept Of BCA, SRNMN College Of Applied Sciences, 4


III SEM C# .NET SHW ETHA Y

Erter no of Candidates: 18
Enter 10 Candidates Name and Height :
Asha
157. 5 usha 126
gi rish
196
aka sh 150
uday 195
smitha
186
fat ha 176
uma 187.7
surya
167
ki can
186
Shortlisted Candidates Height:

Name Height
Asha 157. 5
gi rish 196
uday 195
smitha 186
latha 170
uma 187.7
sunya 167
ki ran 180
Total no of candidates selected 8

4 . Read 10 register numbers randomly and segregate them based on the


course (BA, BSc, BCom, BCA) and semester (first, third or fifth — Analyze the
format of the register numbers as assigned by the university).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace studentregister

class Program

static void Main(string[] args)

Dept Of BCA, SRNMN College Of Applied Sciences,


III SEM C# .NET SHW ETHA Y

string[] regno = new string[10];


Console.WriteLine("Note : The University Register Number Eg - BC192188\n\
tWhere BC = BCA,BS = BSC, BM = BCOM AND BA = BA\n\tin
Register Number 3 and 4 th Character Represents Year (19 Batch in Fifth Semester,
20 Batch in Third Semester, 21 Batch in First Semester)");
Console.WriteLine("Enter 10 Register Numbers: ");
for (int i = 0; i < regno.Length; i++)

regno[i] = Console.ReadLine();

Console.WriteLine("\nRegister Number\tCourse\tSem\tYear");
for (int i = 0; i < regno.Length; i++)

string sem = , year = ", course = regno[i].Substring(0, 2);


//Sem Checking
if (regno[i].Substring(2, 2) == "19")

sem = "Fifth";
year +=
"2019";

else if (regno[i].Substring(2, 2) == "20")

sem = "Third";
year +=
"2020";

else if (regno[i].Substring(2, 2) == "21")

sem = "First";
year +=
"2021";

Dept Of BCA, SRNMN College Of Applied Sciences, 6


III SEM C# .NET SHW ETHA Y

//Course Checking
if (course == "BA")

Dept Of BCA, SRNMN College Of Applied Sciences, 7


III SEM C# .NET SHW ETHA Y

Console.WriteLine("{0}\tBA\t(1}\t(2}", regno[i], sem, year);

else if (course == "BS")

Console.WriteLine("{0}\tBSC\t(1}\t{2}", regno[i], sem, year);

else if (course == "BC")

Console.WriteLine("{0}\tBCA\t(1}\t{2}", regno[i], sem, year);

else if (course == "BM")

Console.WriteLine("{0}\tBCOM\t{1}\t{2}", regno[i], sem, year);

Console.ReadLine();

OUTPUT:

Dept Of BCA, SRNMN College Of Applied Sciences, 8


III SEM C# .NET SHW ETHA Y

5. C# Program to Call Math Operations (any 4) using delegates.


using System;
using System.Collections.Generic;
delegate int MyDeI(int a, int b);
public class MathOperations

public static int Add(int a, int

b) return a + b;

public static int Sub(int a, int

b) return a - b;

public static int Mul(int a, int

b) return a * b;

public static int Div(int a, int b)

return a / b;

class Sample

static void Main()

MyDeI[] opers = ( MathOperations.Add, MathOperations.Sub,


MathOperations.MuI, MathOperations.Div };
int result = 0;
Console.WriteLine("Enter Two Numbers: ");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine("NOTE:\n 0:Add\t 1:Sub\t 2:MuI\t 3:Div");

Dept Of BCA, SRNMN College Of Applied Sciences, 9


III SEM C# .NET SHW ETHA Y

for (int i = 0; i < opers.Length; i++)

result = opers[i](a, b);


Console.WriteLine("Operation[(0}] : (1}", i, result);

Console.ReadLine();

OUTPUT:
Two Numbe s :
iEnten
)2
)NOTE :
0:Add 2:Mul 3 Dżv
1:Sub
Operation[8]
Operation[1]
:
Operation[2j
Operation[3
]

6. Design an option driven program to demonstrate following garbage


collection activities
A) Number of generations
B) Generation number of target object
C) Number of bytes allocated

using System;
public class
Demo

public static void Main(string[]

args) while (true)

Dept Of BCA, SRNMN College Of Applied Sciences, 1


III SEM C# .NET SHW ETHA Y

Console.WriteLine("1.Number of generations\n2.Generation number of target object\


n3.Number of bytes allocated\n4.Exit");
int ch = int.Parse(Console.ReadLine());

Dept Of BCA, SRNMN College Of Applied Sciences, 1


III SEM C# .NET SHW ETHA Y

Demo obj = new Demo();


switch (ch)

case 1:
Console.WriteLine("The number of generations are: (0}\n",
GC.MaxGeneration);
break;
case 2:
Console.WriteLine("The generation number of Demo obj is:
{0}\n",GC.GetGeneration(obj));
break;
case 3:
Console.WriteLine("Number of bytes allocated: (0}\n",
GC.GetTotaIMemory(true));
break;
default:
System.Environment. Exit(0);
break;

OUTPUT:

Dept Of BCA, SRNMN College Of Applied Sciences, 1


III SEM C# .NET SHW ETHA Y

Dept Of BCA, SRNMN College Of Applied Sciences, 1

You might also like