Shadowing in C# using new keyword
1371
25-Mar-2016
We want to use Shadowing in C#. How to use this please help me.
Anonymous User
25-Mar-2016Shadowing 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;
}
}
}