How to C# Interface Inheritance

View: 308    Dowload: 0   Comment: 0   Post by: hanhga   Category: C / C++ / MFC   Fields: Other

In C# Interface Inheritance, an interface can be inherited from other base/parent interfaces. Base interface member can be hidden in its derived interface by same declaration in it and generates a warning message. Warning message can be prevented through the use of “new” keyword with derived interface members

General Syntax:

access-modifier interface Interface1
{
// members
}
access-modifier interface Interface2 : Interface1
{
// members
}

 

Example:

using System;
namespace csharpBasic
{
    // A first interface declaration.
    public interface IMarkSheet
    {
        double GetPercentage(double obtainMarks, double totalMarks);
        double GetTotalMarks
        {
            get;
        }
 
        double GetAspMarks();
        double GetJsMarks();
    }
 
    // Second inteface IMarksheetComponent which inherits first interface IMarkSheet.
    interface IMarksheetComponent : IMarkSheet
    {
        double GetObtainMarks();
    }
 
    // MarkSheet implements second interface IMarksheetComponent.
    class MarkSheet : IMarksheetComponent
    {
        // Fields declaration.
        double AspMarks;
        double JavascriptMarks;
        double TotalMarks = 200;
 
        // Double type read-only property declaration.
        public double GetTotalMarks
        {
            get
            {
                return TotalMarks;
            }
        }
 
        // Parametrized constructor with 2 parameters.
        public MarkSheet(double aspMarks, double javascriptMarks)
        {
            AspMarks = aspMarks;
            JavascriptMarks = javascriptMarks;
        }
 
        // Double return type methods which returns each subject mark.
        public double GetAspMarks()
        {
            return AspMarks;
        }
        public double GetJsMarks()
        {
            return JavascriptMarks;
        }
 
        // Return type method returns obtain marks.
        public double GetObtainMarks()
        {
            return AspMarks + JavascriptMarks;
        }
 
        // Return type method which returns percentage of obtain marks.
        public double GetPercentage(double obtainMarks, double totalMarks)
        {
            return (obtainMarks / totalMarks) * 100.0;
        }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("General mark sheet information:");
            MarkSheet markSheet = new MarkSheet(80, 70);
            Console.WriteLine("Asp.NET marks: {0}", markSheet.GetAspMarks());
            Console.WriteLine("Javascript marks: {0}", markSheet.GetJsMarks());
            double obtainMarks = markSheet.GetObtainMarks();
            Console.WriteLine("Total Marks {0}", markSheet.GetTotalMarks);
            Console.WriteLine("Obtain marks: {0}", obtainMarks);
            Console.WriteLine("Pecentage: {0}", markSheet.GetPercentage(obtainMarks, markSheet.GetTotalMarks));
            Console.ReadKey();
        }
    }
    /*  The Output will be:
      
        General mark sheet information:
        Asp.NET marks: 80
        Javascript marks: 70
        Total Marks 200
        Obtain marks: 150
        Pecentage: 75
 
     */
}

How to C# Interface Inheritance

In C# Interface Inheritance, an interface can be inherited from other base/parent interfaces. Base interface member can be hidden in its derived interface by same declaration in it and generates a warning message. Warning message can be prevented through the use of “new” keyword with derived interface members

Posted on 23-08-2016 

Comment:

To comment you must be logged in members.

Files with category

  • Cronpp - a C++ library for CRON expressions

    Cronpp - a C++ library for CRON expressions

    View: 3    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: Other

    A CRON expression is a string composed of six fields (in some implementation seven), separated by a whites space, representing a time schedule. CRON expressions are used in various job schedulers (such as the Linux job scheduler, the Quartz...

  • Departmental store management system

    Departmental store management system

    View: 5    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: none

    This is a simple project on departmental store management system developed in c++ programming language . This project helps to keep all the information details of the items available in departmental store and maintains the stock and prints the bill....

  • Volume of a Cone in C

    Volume of a Cone in C

    View: 7    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: none

    Code Features: 1. Find the Volume of a cone 2. Find the value of other properties of the cone 3. Teach user how to compute the volume of the cone manually Thanks to following for the code: John Carlo C. Nañoz, Dondon Bagasbas, Gabby Peñones

  • C# - Student & Lecture Test Application (Using Database)

    C# - Student & Lecture Test Application (Using Database)

    View: 6    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: none

    This application was developed by Gopolang Kopano Mathole using visual studio 2013.. Features: - Databases (files as fallback) - Flat UI designs & material designs. - Easy to navigate app. - Login/Register pages (both read and writes to a file). -...

  • Point of Sale and Inventory System C#.Net Version 2.0

    Point of Sale and Inventory System C#.Net Version 2.0

    View: 16    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: none

    This is a complete point of sale and inventory system written in C#.NET. You can use this system to your future project.. System Features Staff/Employee Categories Products Point of Sale Inventory Daily Sales Report By User Daily Sales Report By...

  • Calculator Application Using WPF

    Calculator Application Using WPF

    View: 9    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: none

    Calculator application written in C# using Windows Presentation Foundation. Code is behind the view. Application is using some Static and Explicit resources.

  • Flappy Bird Clone

    Flappy Bird Clone

    View: 26    Download: 0   Comment: 0

    Category: C / C++ / MFC     Fields: none

    Flappy Bird Clone - this was one of the most popular game in the world. The game is very simple, you have to navigate the bird to past the obstacles. You need to tap the screen to make the bird flies. Don’t fly to high because it will die. To get the...

  • Download Manager

    Download Manager

    View: 31    Download: 1   Comment: 0

    Category: C / C++ / MFC     Fields: none

    This program with source code allows you to download any files from the internet. It display the download speed, file size, downloaded bytes, remaining bytes, and the total file size of the file. It also display the progress of the downloaded file...

 
File suggestion for you
File top downloads
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd