LAB EXERCISE 2
Ques. Develop a private dll with Visual Studio.
Ans.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace first_dll
{
public class Class1
{
public static void display(String s)
{
Console.WriteLine("First DLL!!!"+s);
}
}
}
LAB EXERCISE 3
Ques. Develop shared dll using Visual Studio.
Ans.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
[assembly: AssemblyKeyFile("C:\\shared.snk")]
namespace shared_dll
{
public class Class11
{
public static void show()
{
Console.WriteLine("Shared dll");
}
}
}
LAB EXERCISE 4
Ques. Write a program in notepad and compile it using CSC compiler.
Ans.
using System;
namespace CommandCSC
{
class A
{
static void Main()
{
Console.WriteLine("HELLOO!!");
}
}
}
LAB EXERCISE 5
Ques. Create an abstract class shape with length, width, height and radius as fields and Area()
as abstract function and inherited it for Circle, Square and Rectangle class.
[Develop this program in ASP.NET with good look and feel. Use Images wherever
required].
Ans.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public abstract class Shape
{
protected float length;
protected float width;
protected float height;
protected float radius;
abstract public float area();
}
class Circle : Shape
{
public Circle(float r)
{
radius = r;
}
public override float area()
{
return (3.14f * radius * radius);
}
}
class Square : Shape
{
public Square(float h)
{
height = h;
}
public override float area()
{
return (height * height);
}
}
class Rectangle : Shape
{
public Rectangle(float l, float w)
{
length = l;
width = w;
}
public override float area()
{
return (length * width);
}
}
public partial class _Default : System.Web.UI.Page
{
protected void BtnSubmit_Click(object sender, EventArgs e)
{
if ((TxtRadius.Text) != "")
{
float r = (float)Convert.ToDecimal(TxtRadius.Text);
Circle cobj = new Circle(r);
area1.Text = Convert.ToString(cobj.area());
}
if ((TxtSize.Text) != "")
{
float s = (float)Convert.ToDecimal(TxtSize.Text);
Square sobj = new Square(s);
area2.Text = Convert.ToString(sobj.area());
}
if ((TxtLength.Text) != "" && (TxtRadius.Text) != "")
{
float l = (float)Convert.ToDecimal(TxtLength.Text);
float b = (float)Convert.ToDecimal(TxtWidth.Text);
Rectangle robj = new Rectangle(l, b);
area3.Text = Convert.ToString(robj.area());
}
}
}
}
LAB EXERCISE 6
Ques. Demonstrate the Explicit Interface Implementation by creating two or more interfaces
that have same signatures.
Ans.
using System;
interface Italk1
{
void Read();
}
interface Italk2
{
void Read();
}
class Derived:Italk1,Italk2
{
void Italk1.Read()
{
Console.WriteLine("Reading from First Interface");
}
void Italk2.Read()
{
Console.WriteLine("Reading from Second Interface");
}
public static void Main(string[] args)
{
Derived dobj=new Derived();
Italk1 o1=(Italk1)dobj;
Italk2 o2=(Italk2)dobj;
o1.Read();
o2.Read();
Console.ReadKey();
}
}
LAB EXERCISE 7
Ques. Demonstrate the Explicit Interface Implementation by creating two or more interface that
have same signatures with Operator AS.
Ans.
using System;
interface Italk1
{
void Read();
}
interface Italk2
{
void Read();
}
class DerivedItalk1,Italk2
{
void Italk1.Read()
{
Console.WriteLine("Reading from First interface");
}
void Italk2.Read()
{
Console.WriteLine("Reading from Second Interface");
}
public static void Main(string[] args)
{
Derived1 dobj=new Derived1();
Italk1 o1=dobj as Italk1;
Italk2 o2=dobj as Italk2;
o1.Read();
o2.Read();
Console.ReadKey();
}
}