Total Page Preview:   000000000175

What is interfaces in C-Sharp in English and Hindi


Interface in C-Sharp in English

In C#, an interface is a contract between two or more parties, specifying a set of methods, properties, and events that a class must implement. It defines a blueprint of behavior that can be implemented by multiple classes. An interface only contains the declaration of the members, and the implementation is left to the implementing classes.
Here is an example of how to define an interface in C#:
In this example, we define an interface named "IShape". It contains two methods: "Area" and "Perimeter". Any class that implements this interface must implement these two methods.
Here's an example of a class that implements the "IShape" interface:
In this example, we define a class named "Rectangle" that implements the "IShape" interface. The class has two properties: "Length" and "Width". It also implements the "Area" and "Perimeter" methods as required by the "IShape" interface.
Now, we can create an object of the "Rectangle" class and call its "Area" and "Perimeter" methods like this:
In this example, we create an object of the "Rectangle" class, set its "Length" and "Width" properties, and call its "Area" and "Perimeter" methods. The "Area" method returns 50 (10 * 5), and the "Perimeter" method returns 30 (2 * (10 + 5)).


Interface in C-Sharp in Hindi

C# mein, ek interface do ya do se zyada parties ke beech ek contract hota hai jo ek class ke liye implement karna zaruri hota hai. Ye ek behavior ka blueprint define karta hai jo ki multiple classes ke dwara implement kiya jaa sakta hai. Ek interface sirf member ke declaration ko contain karta hai aur uska implementation implementing classes ko chhod diya jaata hai.

Neeche ek example diya gaya hai jisme ek interface ko kaise define kiya jata hai C# mein:

Is example mein, humne "IShape" interface ko define kiya hai. Ismein do methods hain: "Area" aur "Perimeter". Koi bhi class jo is interface ko implement karegi, usse in do methods ko implement karna hoga.
Ab hum ek class ka ek example lete hain jo "IShape" interface ko implement karta hai:
Is example mein, humne "Rectangle" class ko define kiya hai jo "IShape" interface ko implement karta hai. Is class mein do properties hain: "Length" aur "Width". Iske alawa, ye "Area" aur "Perimeter" methods ko implement karta hai jo "IShape" interface ke requirements ke mutabik hain.
Ab hum "Rectangle" class ka object create karte hain aur uske "Area" aur "Perimeter" methods ko invoke karte hain:
Is example mein, humne "Rectangle" class ka object create kiya hai, uske "Length" aur "Width" properties ko set kiya hai, aur uske "Area" aur "Perimeter" methods ko invoke kiya hai. "Area" method 50 (10 * 5) return karta hai aur "Perimeter" method 30 (2 * (10 + 5)) return karta hai.



Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn :





Facebook User: