Dot Net Print 1
Dot Net Print 1
Name: Name:
Signature: Signature:
Date: Date:
1
Rules and Regulation for
Digital / Computer Lab User
3
Lab 1
Console.ReadLine()
using System;
namespace Lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input: ");
string input = Console.ReadLine();
Console.WriteLine($"Output: {input}");
Console.ReadKey();
}
}
}
Console.Read()
using System;
4
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input: ");
Console.Write("Output: " + Convert.ToChar(Console.Read()));
Console.ReadKey();
}
}
}
Output:
Console.Write()
using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("I am students ");
Console.Write("of ");
Console.Write("JMC COllege");
Console.ReadKey();
}
}
}
Console.WriteLine()
using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
5
{
Console.WriteLine("I am Students ");
Console.WriteLine("of ");
Console.WriteLine("JMC College");
Console.ReadKey();
Console.ReadKey();
}
}
}
Lab 2
Write a program to add numbers x, y and z. One function to add x and y another
function to add all three numbers. Print on screen as given output.
Sum of 5 and 6 = 11
Sum of 5, 6 and 7 = 18
using System;
namespace lab2
{
class Program
6
{
public void Add(int x, int y)
{
Console.WriteLine("Sum of {0} and {1} = {2}", x, y, (x + y));
}
Lab 3
Write a program to implement the concept of default constructor, parameterized
constructorand private constructor in C#.
Default Constructor in C#
using System;
namespace DefaultConstractor
{
class addition
{
int a, b;
7
public addition() {
a = 100;
b = 175;
}
Parameterized Constructor in C#
using System;
namespace Constructor
{
class paraconstrctor
{
public int a, b;
class MainClass
{
8
static void Main()
{
paraconstrctor v = new paraconstrctor(100, 175);
Console.WriteLine("-----------parameterized constructor example by
vithal wadje---------------");
Console.WriteLine("\t");
Console.WriteLine("value of a=" + v.a);
Console.WriteLine("value of b=" + v.b);
Console.Read();
}
}
}
Private Constructor in C#
using System;
namespace defaultConstractor
{
public class Counter
{
private Counter() {
}
class viewCountedetails
{
9
static void Main()
{
Console.WriteLine("-------Private constructor example by vithal
wadje----------");
Console.WriteLine();
Counter.currentview = 500;
Counter.visitedCount();
Console.WriteLine("Now the view count is: {0}",
Counter.currentview);
Console.ReadLine();
}
}
}
Lab 4
using System;
namespace lab4
{
namespace BinaryOverload
{
class Calculator
{
public int number = 0;
public Calculator() { }
public Calculator(int n)
{
number = n;
}
10
public static Calculator operator +(Calculator Calc1, Calculator Calc2)
{
Calculator Calc3 = new Calculator(0);
Calc3.number = Calc2.number + Calc1.number;
return Calc3;
}
Lab 5
Multiple Inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MultipleInheritApplication
{
interface calc1
{
int add(int a, int b);
}
interface calc2
{
int sub(int x, int y);
}
11
interface calc3
{
int mul(int r, int s);
}
interface calc4
{
int div(int c, int d);
}
class Program
{
static void Main(string[] args)
{
Calculation c = new Calculation();
c.add(8, 2);
c.sub(20, 10);
c.mul(5, 2);
c.div(20, 10);
12
Console.WriteLine("Subtraction: " + c.result2);
Console.WriteLine("Multiplication :" + c.result3);
Console.WriteLine("Division: " + c.result4);
Console.ReadKey();
}
}
}
Multilevel Inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Son : Father
{
public void DisplayTwo()
{
Console.WriteLine("Son.. ");
}
13
Console.Read();
}
}
class Grandfather
{
public void Display()
{
Console.WriteLine("Grandfather...");
}
}
Lab 6
Overiding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OverridingExample
{
class Subject // Base class
{
public virtual void study() // Base class method
{
Console.WriteLine("Study all the subjects");
}
}
14
class Mathematics : Subject // Derived class
{
public override void study() // Derived class method
{
base.study(); // Calls the base class method
Console.WriteLine("Study Mathematics");
}
}
class Program
{
// Main method
static void Main(string[] args)
{
Mathematics m = new Mathematics();
m.study();
Console.ReadLine();
}
}
}
Overloading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OverloadingExample
{
class Demo
{
public int Sum(int x, int y)
{
int value = x + y;
return value;
}
15
}
Console.ReadLine();
}
}
}
16