shikha rc sharp file
Post on 11-Dec-2015
222 Views
Preview:
DESCRIPTION
TRANSCRIPT
LAB EXERCISE 1
Ques. Develop an exe with Visual Studio.
Ans.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str;
Console.WriteLine("Enter your name");
str = Console.ReadLine();
Console.WriteLine("The name entered is: "+ str);
Console.ReadKey();
}
}
}
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);
}
}
}
The console application which uses this dll will be:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace console
{
class Program
{
static void Main(string[] args)
{
first_dll.Class1.display("shristi");
Console.WriteLine("hey");
}
}
}
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 ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<Table Border="2" width="700Px">
<tr>
<td class="style1"><asp:Image runat="server" ID="ImgCircle"
ImageUrl="~/circle.jpg"> </asp:Image> </td>
<td><asp:Label runat="server" ID="LabRadius" Text="Radius"></asp:Label></td>
<td><asp:TextBox runat="server" ID="TxtRadius"></asp:TextBox></td>
<td>Area:<asp:Label runat="server" ID="LabCircleArea"></asp:Label></td>
<td><asp:Label ID="area1" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td class="style1"><asp:Image runat="server" ID="ImgSquare"
ImageUrl="~/square.png"> </asp:Image> </td>
<td><asp:Label runat="server" ID="LabSize" Text="Size"></asp:Label></td>
<td><asp:TextBox runat="server" ID="TxtSize"></asp:TextBox></td>
<td>Area:<asp:Label runat="server" ID="LabSquareArea"></asp:Label></td>
<td><asp:Label ID="area2" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td class="style1"><asp:Image runat="server" ID="Image1"
ImageUrl="~/rectangle.png"> </asp:Image> </td>
<td><asp:Label runat="server" ID="LabLength" Text="Length"></asp:Label><br/>
<asp:Label runat="server" ID="LabWidth" Text="Width"></asp:Label>
</td>
<td><asp:TextBox runat="server" ID="TxtLength"></asp:TextBox><br/>
<asp:TextBox runat="server" ID="TxtWidth"></asp:TextBox>
</td>
<td>Area:<asp:Label runat="server" ID="LabRectArea"></asp:Label></td>
<td><asp:Label ID="area3" runat="server" Text=""></asp:Label></td>
</tr>
<tr><td align="center" colspan="4"><asp:Button runat="server" ID="BtnSubmit"
Text="Submit" onclick="BtnSubmit_Click"> </asp:Button>
</td>
</tr>
</Table>
</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(); } }
top related