Home > DeveloperSection > Forums > Shadowing in C# using new keyword
Norman Reedus
Norman Reedus

Total Post:45

Points:315
Posted on    March-25-2016 10:54 PM

 C# C# 
Ratings:


 1 Reply(s)
 252  View(s)
Rate this:
We want to use Shadowing in C#. How to use this please help me.


aditya kumar Patel

Total Post:250

Points:1782
Posted on    March-25-2016 11:02 PM

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;

}

}

}


Don't want to miss updates? Please click the below button!

Follow MindStick