Download presentation
Presentation is loading. Please wait.
Published byFranklin Terry Modified over 9 years ago
2
Features of Object Oriented Programming:
6
A class is a collection of things which posses common similarities. In C#.NET a class is a user defined Data type and is Known as Reference Type. A class can contain following members in C#.NET A class is a collection of things which posses common similarities. In C#.NET a class is a user defined Data type and is Known as Reference Type. A class can contain following members in C#.NET
7
It’s used to store the data related to the class. Except Data Fields no other member of a class can store the data. To declare any Data Field, we use the following
11
1 2 2
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ClsEmployee1 { class Program { int eid, eage; string ename, eaddress; public Program() { this.eid = 101; this.ename = "sai"; this.eaddress = "mcl"; this.eage = 24; } public void DisplayEmpData() { Console.WriteLine("eida is "+eid); Console.WriteLine("ename is"+ename); Console.WriteLine("eaddress is " +eaddress); Console.WriteLine("eage is" + eage); } class ClsUDConst { static void Main(string[] args) { Program obj1 = new Program(); Program obj2 = new Program(); obj1.DisplayEmpData(); obj2.DisplayEmpData(); Console.Read(); }
14
[ ] class : Class Class1 { Members } Class Class2 : Class1 { Consume the parent members here }
15
Example program
21
1 Read Only Property 2 Write Only Property 3 Read Write property This property is used to read the data from the Data field It is used to write the data into Data field of a class. It is used to read the data from the Data field and to write the data in to the Data Field
22
Access Modifier Data Type property Name { set { Data Field Name=Value; } get { return data Field Name; } Namespace CAProperties { Class clsEmpolyee { int EmpId,EAge; Public int PEmpId { set { EmpId=value; } get { return EmpId; }
23
Public int PEAge { set { EAge=Value; } get { return EAge; } Class ClsProperty1 { Static void Main(string[] args) { clsEmployee obj1=new clsEmployee(); Console.write(“Enter Employee details:”); Obj1.PEmpId=Concert.ToInt32(Console.ReadLine()); Obj1.PEAge=convert.ToInt32(console.ReadLine()); }
25
In the.NET Framework, interfaces have a special naming convention. All interface name begin with a capital I. Interfaces can have properties as we difference from a class. 1.You cannot create an object of an interface 2.An interface does not contain any constructor. 3.All methods in an interface are abstract. 4.An interface can inherit multiple interfaces.
27
Public void Div (int x, int y) { Console.Writeline(x/y) } public void Test () { Console.Writeline (“Declared under multiple interfaces”); } Void Inter1.Test () { Console.Writeline (“Method of Interfaced 1”); } Void Inter2.Test () { Console.Writeline (“Method of Interfaced 2”); } Public void Div (int x, int y) { Console.Writeline(x/y) } public void Test () { Console.Writeline (“Declared under multiple interfaces”); } Void Inter1.Test () { Console.Writeline (“Method of Interfaced 1”); } Void Inter2.Test () { Console.Writeline (“Method of Interfaced 2”); } Static Void Main () { Inter class obj= new Inter class (); Obj. Add (100, 45); Obj. Sub (100, 45); Obj. Mul (100, 45); Obj.Div (100, 45); Obj. Test (); Inter1 i1 = obj; Inter i2 = obj; I1.Test (); i2.Test (); Console.ReadLine (); } Static Void Main () { Inter class obj= new Inter class (); Obj. Add (100, 45); Obj. Sub (100, 45); Obj. Mul (100, 45); Obj.Div (100, 45); Obj. Test (); Inter1 i1 = obj; Inter i2 = obj; I1.Test (); i2.Test (); Console.ReadLine (); }
32
Add a class del.cs and write the following the code Class Delclass { Public String SayHello(string name0 { Return “Hello” +name; } Public delegate string SayDel(String name); Static void Main() { Delclass obj=new Delclass(); SayDel Sd=new SayDel(obj.sayHellow); Console.WriteLine(Sd(“xxx”)); Console.WrireLine(Sd(“yyy”)); Console.WrireLine(Sd(“zzz”)); Console.ReadLine(); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.