C# में मल्टीपल इनहेरिटेंस समर्थित नहीं है। मल्टीपल इनहेरिटेंस लागू करने के लिए इंटरफेस का उपयोग करें।
क्लास Shape में हमारा इंटरफेस PaintCost है:
public interface PaintCost { int getCost(int area); }Shape हमारा बेस क्लास है जबकि Rectangle डेराइव्ड क्लास है:
class Rectangle : Shape, PaintCost { public int getArea() { return (width * height); } public int getCost(int area) { return area * 80; } }C# में मल्टीपल इनहेरिटेंस के लिए इंटरफेस लागू करने का पूर्ण कोड:
using System; namespace MyInheritance { class Shape { public void setWidth(int w) { width = w; } public void setHeight(int h) { height = h; } protected int width; protected int height; } public interface PaintCost { int getCost(int area); } class Rectangle : Shape, PaintCost { public int getArea() { return (width * height); } public int getCost(int area) { return area * 80; } } class RectangleDemo { static void Main(string[] args) { Rectangle Rect = new Rectangle(); int area; Rect.setWidth(8); Rect.setHeight(10); area = Rect.getArea(); // ऑब्जेक्ट का क्षेत्र प्रिंट करें Console.WriteLine("Total area: {0}", Rect.getArea()); Console.WriteLine("Total paint cost: ${0}", Rect.getCost(area)); Console.ReadKey(); } } }