
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How do you make code reusable in C#?
To make code reusable in C#, use Interfaces. Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow.
For example, Shape Interface −
public interface IShape { void display(); }
Above we have declared an Interface Shape. You can notice that it begins with a capital “I”. It is a common convention that interfaces names begin with “I”.
We have not added an access specifier above since interface members are public by default.
In real applications, Polymorphism is key for code reuse. Interfaces are flexible because if you use interfaces, then with its help you can pass anything that implements that Interface.
- Related Articles
- How do you code a vending machine in Python?
- How do you make an array in Python?
- How do you make a list iterator in Java?
- How do you use Python to make websites?
- How do you make a higher order function in Python?
- How do you make a button that adds text in HTML ?
- How do you make a shallow copy of a list in Java?
- How do you make a string in PHP with a backslash in it?
- How to deal with reusable components in Selenium Java?
- How do you run your own code alongside Tkinter's event loop?
- How do you make a separation and divorce as amicable as possible?
- How do you make Selenium 2.0 wait for the page to load?
- What will you do to make your man go crazy in love with you?
- How can you make people listen to you?
- With the help of an activity suggest how you can make your magnetic compass. What do you conclude?
