Dotnet
Dotnet
Dotnet
Console.ReadLine()
Source Code:
using System;
namespace Lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input: ");
string input = Console.ReadLine();
Console.WriteLine($"Output: {input}");
Console.ReadKey();
}
}
}
Output:
Console.Read()
Source Code:
using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input: ");
Console.Write("Output: " + Convert.ToChar(Console.Read()));
Console.ReadKey();
}
}
}
Output:
Console.Write()
Source Code:
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();
}
}
}
Output:
Console.WriteLine()
Source Code:
using System;
namespace lab1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("I am Students ");
Console.WriteLine("of ");
Console.WriteLine("JMC College");
Console.ReadKey();
Console.ReadKey();
}
}
}
Output:
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
Source Code:
using System;
namespace lab2
{
class Program
{
public void Add(int x, int y)
{
Console.WriteLine("Sum of {0} and {1} = {2}", x, y, (x + y));
}
Output:
Lab 3
Write a program to implement the concept of default constructor, parameterized
constructorand private constructor in C#.
Default Constructor in C#
Source Code:
using System;
namespace DefaultConstractor
{
class addition
{
int a, b;
public addition() {
a = 100;
b = 175;
}
Output:
Parameterized Constructor in C#
Source Code:
using System;
namespace Constructor
{
class paraconstrctor
{
public int a, b;
class MainClass
{
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();
}
}
}
Output:
Private Constructor in C#
Source Code:
using System;
namespace defaultConstractor
{
public class Counter
{
private Counter() {
}
class viewCountedetails
{
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();
}
}
}
Output:
Lab 4
Source Code:
using System;
namespace lab4
{
namespace BinaryOverload
{
class Calculator
{
public int number = 0;
public Calculator() { }
public Calculator(int n)
{
number = n;
}
Multiple Inheritance
Source Code:
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);
}
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);
Output:
Multilevel Inheritance
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo
{
class Son : Father
{
public void DisplayTwo()
{
Console.WriteLine("Son.. ");
}
class Grandfather
{
public void Display()
{
Console.WriteLine("Grandfather...");
}
}
Overiding
Source Code:
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");
}
}
class Program
{
// Main method
static void Main(string[] args)
{
Mathematics m = new Mathematics();
m.study();
Console.ReadLine();
}
}
} Output:
Overloading
Source Code:
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;
}
Console.ReadLine();
}
}
}
Output: