SHADOWING IN C# USING NEW KEYWORD

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
C# 
C#
 532  View(s)
Ratings:
Rate this:
We want to use Shadowing in C#. How to use this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    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;

    }

    }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!