Inheriting and extending .NET types

.NET has prebuilt class libraries containing hundreds of thousands of types. Rather than creating your own completely new types, you can often start by inheriting from one of Microsoft's.

Inheriting from the Exception class

In the Ch06_PacktLibrary project, add a new class named BankAccountException, as shown in the following code:

using System;

namespace Packt.CS6
{
    public class BankAccountException : Exception
    {
        public BankAccountException() : base() { }
        public BankAccountException(string message) : base(message) { }
        public BankAccountException(string message, Exception innerException) : base(message, innerException) { }
    }
}

In the BankAccount class that you created in the previous chapter, add the following method: ...

Get C# 6 and .NET Core 1.0: Modern Cross-Platform Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.