Sie sind auf Seite 1von 10

1.) using System.Collections.Generic; using System.Linq; using System.

Text; namespace ConsoleApplication25 { class Program { static void Main(string[] args) { fun obj = new fun(); int a, b; Console.WriteLine("enter 2 num"); a=int.Parse(Console.ReadLine()); b =int.Parse(Console.ReadLine()); //Console.WriteLine(obj.show(a,b));

Console.WriteLine("addition=" + obj.add(a, b)); Console.WriteLine("substractio=" + obj.sub(a, b)); Console.WriteLine("multi=" + obj.mul(a, b)); Console.WriteLine("divison=" + obj.div(a, b)); } } class fun { public int add(int x,int y) { return x + y; }

public int sub(int x, int y) { return x - y; }

2.) using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication36 { class Program { static void Main(string[] args) { fun_overload obj = new fun_overload(); obj.area(10, 20); obj.area(10, 20, 30); obj.circle(5); obj.tri(5,6); } } } class fun_overload { public void area(int x, int y) { Console.WriteLine("square=" + (x * y)); } public void area(int x, int y, int z) { Console.WriteLine("Rectangle=" + (x * y * z)); } public void circle(int x) { Console.WriteLine("circle=" + (3.14 * x * x)); } public void tri(int x, int y) { Console.WriteLine("triangle=" + (0.5 * x * y)); } }

3.constructor int a, b; Console.WriteLine("enter 2 nos"); a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); maths obj = new maths(a,b); Console.WriteLine("addition of 2 nos = " + obj.add()); Console.WriteLine("subtraction of 2 nos = " + obj.sub()); Console.WriteLine("multiplication of 2 nos = " + obj.multi()); float c, d; Console.WriteLine("enter 2 decimal nos"); c = float.Parse(Console.ReadLine()); d = float.Parse(Console.ReadLine()); maths obj1 = new maths(c, d); Console.WriteLine("division of 2 nos = " + obj1.div()); } } class maths { int p, q; float c, d; public maths(int x,int y) { p = x; q = y; } public maths(float x, float y) { c = x; d = y; } public int add() { return p + q; } public int sub() { return p - q; } public int multi() {

return p * q; } public float div() { return c / d; } public void show() { Console.WriteLine("c= " + c + "d = " + d); } } } 4.) constructor with parameter(inheritance) using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication32 { class Program { static void Main(string[] args) { child obj = new child(); obj.show(); child o = new child("welcome","to c#"); } } class base1 { public base1() { Console.WriteLine("Base class Constructor"); } public void show() { Console.WriteLine(" Base class Show method"); }

public base1(string str) { Console.WriteLine("base class="+ str); } } class child : base1 { public child() : base() { Console.WriteLine("CHILD CLASS CONSTRUCTOR "); } public new void show() { base.show(); { Console.WriteLine("child class method"); } } public child(string str, string s) : base(str) { Console.WriteLine("child class=" + str+s); } } } 5. function overloading _________________________ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication27 { class Program { static void Main(string[] args) { fun_overload obj=new fun_overload(); obj.add(10,20); obj.add(10,20,30); Console.WriteLine(obj.multi(5, 5));

Console.WriteLine(obj.multi(5,5, 5)); } } } class fun_overload { public void add(int x, int y) { Console.WriteLine("add=" + (x + y)); } public void add(int x, int y, int z) { Console.WriteLine("add=" + (x + y + z)); } public int multi(int x, int y) { return (x * y); } public int multi(int x, int y, int z) { return (x * y * z); } } 6.) function returning values using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication36 { class Program { static void Main(string[] args) { fun_overload obj = new fun_overload(); obj.area(10, 20); obj.area(10, 20, 30); Console.WriteLine(obj.area(10)); Console.WriteLine(obj.area(10.2f,20));

} } } class fun_overload { public void area(int x, int y) { Console.WriteLine("square=" + (x * y)); } public void area(int x, int y, int z) { Console.WriteLine("Rectangle=" + (x * y * z)); } public double area(float x) { return( (3.14 * x * x)); } public double area(float x, int y) { return ( (0.5 * x * y)); } } 7. inheritance with constructor using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication32 { class Program { static void Main(string[] args) { child obj = new child(); obj.show(); }

} class base1 { public base1() { Console.WriteLine("Base class Consttructor"); } public void show() { Console.WriteLine(" Base class Show method"); } } class child:base1 { public child():base() { Console.WriteLine("CHILD CLASS CONSTRUCTOR "); } public new void show() { base.show(); { Console.WriteLine("child class method"); } } } } 8.) constructor using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication28 { class program { static void Main(string[] args) { int p,q; test obj=new test(); obj.add();

Console.WriteLine("Enter 2 nos"); p=int.Parse(Console.ReadLine()); q=int.Parse(Console.ReadLine()); test obj1=new test(p,q); obj1.add(); } } class test { int x, y; public test() { x=10; y=20; } public void add() { Console.WriteLine("Add"+(x+y)); } public test(int a,int b) { x=a; y=b; }

} } 9. single inheritance using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections;

namespace ConsoleApplication30 { class Program { static void Main(string[] args) { derivedclass obj = new derivedclass(); obj.print3no(10, 20, 30); int sum = obj.findsum(10, 20); Console.WriteLine("Sum=" + sum); } } class Baseclass { public int findsum(int x, int y) { return (x + y); } protected void print(int x, int y) { Console.WriteLine("1st no=" + x); Console.WriteLine("2nd no=" + y); } } class derivedclass : Baseclass { public void print3no(int x, int y, int z) { print(x, y); Console.WriteLine("3rd no="+z); } } }

Das könnte Ihnen auch gefallen