C# abstract keyword

Search for a command to run...

No comments yet. Be the first to comment.
In this article, we would learn about virtual, override and new keyword. Before moving further to understand about virtual, override and new , it's important to understand how polymorphism is achieved in c#. What is polymorphism? The word polymorphis...
ASP.NET Core Configuration Guide Overview ASP.NET Core uses a layered configuration system where later sources override earlier ones for the same key. Configuration Priority Order Priority Source
Legacy Delphi applications often struggle with outdated UI/UX, performance issues, and monolithic architectures that make refactoring difficult. However, a full rewrite is not always feasible due to time, cost, and the risk of disrupting critical bus...
Entity Framework Core (EF Core) is a powerful and flexible object-relational mapping (ORM) framework for .NET applications, enabling developers to work with relational databases using strongly-typed .NET objects. It simplifies data access by abstract...

In this article we are going to cover some advance scenarios where Options pattern is very useful. We have covered the basic understanding of Options pattern into Options pattern in ASP.NET Core: Introduction article. Please go through it if not fami...

In this article we will learn about Options pattern in ASP.NET Core for dealing with application configurations. The Options pattern uses the C# classes to access and manage the configurations thus providing more flexibility and type safe approach to...

In this tutorial, we would learn about abstract keyword in c# programming language.
abstract: This modifier indicates that thing being modified has a missing or incomplete implementation.
This modifier in C# language applies to the following :
Class
Method
Properties
Indexers
Events
A class declared with abstract modifier is an abstract class.
abstract classes are intended to be a base class of other classes - the developer can not create an Object of an abstract class.
an abstract class can have both abstract methods ( methods with definition) and non-abstract methods (methods without definition).
As an object can not be created for an abstract class, a derived class must be created for an abstract class.
public abstract class Asset {
public abstract decimal BuyPrice { get; }
public abstract decimal SellPrice { get; }
public abstract decimal CalculateProfit();
}
public class Stock : Asset {
public override decimal BuyPrice => 100;
public override decimal SellPrice => 150;
public override decimal CalculateProfit() {
return (SellPrice - BuyPrice);
}
}
An abstract class must provide implementation for all interface members
An abstract class that implements an interface might map the interface methods onto abstract methods.
interface I {
void M();
}
abstract class C : I {
public abstract void M();
}
abstract method declaration doesn't provide any implementation.
public abstract class Asset {
public abstract decimal CalculateProfit();
}
An abstract method is implicitly a virtual method - base class must provide its implementation.
It is an error to use static or virtual modifiers in an abstract method declaration.
Abstract method declarations are only permitted in abstract classes.

Abstract properties behave like abstract methods, except for the differences in declaration and invocation syntax..
That's it for this article. Thanks for reading this, please share your feedback in the comments section below.