How to C# Interface Inheritance

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

0 point/0 review File has been tested

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

How to C# Interface Inheritance Posted on 23-08-2016  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 5/10 230

Comment:

To comment you must be logged in members.

Files with category

  • An autonomous and concealed IPC mechanism

    An autonomous and concealed IPC mechanism

    View: 69    Download: 0   Comment: 0

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

    What if you have one or more modules, running independently in a system, which should collaborate between each other? Well, they will have to be able to exchange data, organized as events, messages or packets of some sort.

  • How to Swap Two Numbers using Call by Reference in C

    How to Swap Two Numbers using Call by Reference in C

    View: 570    Download: 0   Comment: 0

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

    How to swap two numbers using call by reference in C , C++. In the interviews interviewer generally asked the difference between call by reference and call by value

  • How to Print Fibonacci Series using Recursion in C, C++

    How to Print Fibonacci Series using Recursion in C, C++

    View: 568    Download: 0   Comment: 0

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

    Write a program to print Fibonacci Series using recursion. Fibonacci series is a very important program in terms of interviews. To make this program little tough interviewer ask to write a fibonacci series code using recursion.

  • How to Implicitly Typed Arrays In C#

    How to Implicitly Typed Arrays In C#

    View: 633    Download: 0   Comment: 0

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

    When we initialize these type of arrays with any data type, the compiler convert these arrays into that data type at compile time.

  • How to C# Static vs Instance Methods As Event Handlers

    How to C# Static vs Instance Methods As Event Handlers

    View: 435    Download: 0   Comment: 0

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

    Both static and instance methods can be used as event handlers in C#

  • Build Pass By Reference To Method In C#

    Build Pass By Reference To Method In C#

    View: 590    Download: 0   Comment: 0

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

    Like value types such as int, double, char etc. We can also pass a reference variable to the method in C# as its parameter which allows us to pass an object to the method and it is called pass by reference to method in C#.

  • How to C# Continue Statement

    How to C# Continue Statement

    View: 410    Download: 0   Comment: 0

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

    continue statement skips or exits the current execution of a loop by given condition and keep execution continue for its next iteration unlike break statement it does not exit or terminate from loops, it terminates only its current execution

  • How to Single Dimensional Arrays In C#

    How to Single Dimensional Arrays In C#

    View: 367    Download: 0   Comment: 0

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

    Single Dimensional Arrays in C# store each individual element at their single dimension, position or a specific location, that location is called an array index. Each index describes the position of each element within an array. Each element in an...

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