kunal c sharp file

Upload: kuku288

Post on 10-Jan-2016

222 views

Category:

Documents


0 download

DESCRIPTION

c # file

TRANSCRIPT

  • Lab Exercise :- 1

    Ques. Develop an exe with Visual Studio.

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace proj3 { class Program { static void Main(string[] args) { Console.WriteLine("This is the simple executable File "); Console.ReadKey(); } } }

  • Lab Exercise :- 2

    Ques. Develop a private dll with Visual Studio.

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyLib1 { public class MyClass { public static void display(String s) { Console.WriteLine("Hello .."+s+"This is the Display Function of MyClass of MyLib1.dll"); } } }

    Use the created dll classes in our file

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace console { class Program { static void Main(string[] args) { MyLib1.MyClass.display("KuKu"); Console.WriteLine("Main Exited"); } }}

  • Lab Exercise :- 3

    Ques. Develop shared dll using Visual Studio.

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; [assembly: AssemblyKeyFile("D:\\programs\\Dot Net\\key1.snk")] namespace MyLib1 { public class MyClass { public static void display(String s) { Console.WriteLine("Hello .."+s+"This is the Display Function of MyClass of MyLib1.dll"); } } }

    Key is created for strong name of MyLib1.dll

  • Lab Exercise :- 4

    Ques. Write a program in notepad and compile it using CSC compiler.

    using System;

    namespace Outer

    {

    public class MyClass

    {

    static void Main()

    {Console.WriteLine("Main Method of My Class");}

    }

    }

  • 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].

    Area:

    Area:

    Area:

  • 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());

    } } } }

  • Ques. Demonstrate the Explicit Interface Implementation by creating two or more interfaces that

    have same signatures.

    using System;

    interface Italk1

    {

    void Read();

    }

    interface Italk2

    {

    void Read();

    }

    class Derived1: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();

    }

    }

    Ques. Demonstrate the Explicit Interface Implementation by creating two or more interface that

    have same signatures with Operator AS.

    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)

    {

    Derived1 dobj=new Derived1();

    Italk1 o1=dobj as Italk1;

  • Italk2 o2=dobj as Italk2;

    o1.Read();

    o2.Read();

    Console.ReadKey();

    }

    }