I have two classes like Class A and Class B. Class A have some properties, methods and Class B have only the properties. But both Classes have the same set of properties.
My Question is, If I add any new property in Class A, I need to add that in Class B also. If I did not add means, need to show error. How can I achieve this through C#?
You can go with the abstract class. The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.
Here is a simple example related to your question However you can understand and learn about Abstract classes here : Abstract Class
Output of the above program is:
Hope this helps you.
You may achieve this by using an Interface and implementing it both in class A and class B. In the interface, define the property that is required in class A and B:
Or you can use keyword
abstract
to create a class in common for A and B.