Data Sadowing

Shadowing :- This is a .Net Concept by which you can provide a new implementation for the base class member without overriding the member. You can shadow a base class member in the derived class by using the keyword Shadows . The method signature access level and return type of the shadowedmember can be completely different than the base class member.

Note:-overriding is used to redefines only the methods. but shadowing redefines the entire element.

C# coding

using System;

namespace ConsoleApplication19
{
class Shadow
{
static int x = 1;
static void Main(string[] args)
{
int x = 10;
//--- prints local, not class variable.

Console.WriteLine("main: x" + x);
//--- prints class, not local variable.

Console.WriteLine("main sahdow x:" + Shadow.x);

printa();
printb(100);
}

static void printa()
{
//--- prints x in enclosing scope, not x in caller.

Console.WriteLine("printa x:" + x);
}

static void printb(int x)
{
//--- Parameters are like local variables.

Console.WriteLine("printb x:" + x);
}
}
}

Produces the following output.

main : x = 10
main : Shadow.x = 1
printa: x = 1
printb: x = 100