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

A Practical File OF: Submitted To: Submitted by

Uploaded by

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

A Practical File OF: Submitted To: Submitted by

Uploaded by

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

A

PRACTICAL FILE
OF
.NET

SUBMITTED TO : SUBMITTED BY :
MRS. VENU MAM POOJA
[ASSISTANT PROFESSOR] MCA-3rd SEM
UNIVERSITY ROLL NO. 23128410055
1. Write a Program of Basic C# console application
statement iterative statement.
using System;
namespace ControlFlowDemo
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("Welcome to C#.NET");
}

Console.WriteLine("Some Other Statement");


Console.ReadKey();
}
}
}
Output :-
Welcome to C#.NET
Welcome to C#.NET
Welcome to C#.NET
Welcome to C#.NET
Welcome to C#.NET
Some Other Statement
2. Implement of Jagged Array.

using System;
class GFG {
// Main Method
public static void Main()
{
// Declare the Jagged Array of four elements:
int[][] jagged_arr = new int[4][];

// Initialize the elements


jagged_arr[0] = new int[] { 1, 2, 3, 4 };
jagged_arr[1] = new int[] { 11, 34, 67 };
jagged_arr[2] = new int[] { 89, 23 };
jagged_arr[3] = new int[] { 0, 45, 78, 53, 99 };

// Display the array elements:


for (int n = 0; n < jagged_arr.Length; n++) {
// Print the row number
System.Console.Write("Row({0}): ", n);

for (int k = 0; k < jagged_arr[n].Length; k++) {

// Print the elements in the row


System.Console.Write("{0} ",
jagged_arr[n][k]);
}
System.Console.WriteLine();
}
}
}

Output :
Row(0): 1 2 3 4
Row(1): 11 34 67
Row(2): 89 23
Row(3): 0 45 78 53 99
3. Demonstration the use of static class, static data
members.
// C++ Program to demonstrate the use of
// static data members
#include <iostream>
using namespace std;

// class definition
class A {
public:
// static data member here
static int x;
A() { cout << "A's constructor called " << endl; }
};

// we cannot initialize the static data member inside the


// class due to class rules and the fact that we cannot
// assign it a value using constructor
int A::x = 2;
// Driver code
int main()
{
// accessing the static data member using scope
// resultion operator
cout << "Accessing static data member: " << A::x
<< endl;

return 0;
}

Output :
Accessing static data member: 2
4. Write a program to implement the prostatic
properties or private field in c #.
using System;

public class Person


{
// Private field
private string _name;

// Public property with a getter and setter


public string Name
{
get { return _name; }
set
{
if (!string.IsNullOrEmpty(value))
{
_name = value;
}
else
{
Console.WriteLine("Name cannot be empty.");
}
}
}

// Constructor
public Person(string name)
{
Name = name;
}

// Method to display the name


public void Display()
{
Console.WriteLine("Name: " + Name);
}
}
public class Program
{
public static void Main()
{
// Create a new Person object
Person person = new Person("John Doe");

// Display the name


person.Display();

// Try to set an empty name


person.Name = "";

// Display the name again


person.Display();
}
}

Output :
Name: John Doe
Name cannot be empty.
Name: John Doe

5. Write a program to implement structure in c # for


preventing the value of student employee with
constructor.
using System;

struct StudentEmployee
{
public readonly string Name;
public readonly int ID;
public readonly double Salary;

// Constructor to initialize the values


public StudentEmployee(string name, int id, double salary)
{
Name = name;
ID = id;
Salary = salary;
}
// Method to display the details
public void DisplayDetails()
{
Console.WriteLine($"Name: {Name}");
Console.WriteLine($"ID: {ID}");
Console.WriteLine($"Salary: {Salary}");
}
}

class Program
{
static void Main()
{
// Creating an instance of StudentEmployee
StudentEmployee employee = new
StudentEmployee("John Doe", 12345, 50000.0);

// Displaying the details


employee.DisplayDetails();
}
}

Output :
Name: John Doe
ID: 12345
Salary: 50000

You might also like