Shadowing in C# using new keyword

Total Post:45

Points:315
C# 
C#
 831  View(s)
Ratings:
Rate this:
We want to use Shadowing in C#. How to use this please help me.
  1. Post:281

    Points:2003
    Re: Shadowing in C# using new keyword

    Shadowing is concept to hide functionality provided by base class member. We can also change return type of member also. In overriding we can only change definition but in shadowing we can change return type also

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    namespace Shadowing

    {

    class Program

    {

    static void Main(string[] args)

    {

    ChildClass obj = new ChildClass();

    obj.GetInvoice();

    Console.ReadLine();

    }

    }

    public class BaseClass {

    public int InvoiceNumber = 10;

    public virtual void GetInvoice()

    {

    Console.WriteLine("This is Base Class Data");

    }

    }

    public class ChildClass:BaseClass

    {

    public new string InvoiceNumber = "10";

    public new string GetInvoice()

    {

    Console.WriteLine("This is Child Class Data");

    return string.Empty;

    }

    }

    }

      Modified On Apr-11-2018 03:21:34 AM

Answer