- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are abstract properties in C#?
An implementation of the property accessors will not be provided by an abstract property declaration.
Let us see how to learn how to work with abstract properties. Here we have an abstract class Shape with two derived classes: Square and Circle.
Here, we have an abstract Area property.
The following is the Circle class.
Example
public class Circle : Shape { private int radius; public Circle(int radius, string id) : base(id) { this.radius = radius; } public override double Area { get { return radius * radius * System.Math.PI; } } }
In the same way, the Square class.
Example
public class Square : Shape { private int side; public Square(int side, string id) : base(id) { this.side = side; } public override double Area { get { return side * side; } } }
The following is the Shape class, which is abstract.
Example
public abstract class Shape { private string name; public Shape(string s) { Id = s; } public string Id { get { return name; } set { name = value; } } public abstract double Area { get; } public override string ToString() { return Id + " Area = " + string.Format("{0:F2}", Area); } }
Advertisements