Hello all,
I am new to C# and learning concepts . I got this doubt and Thought i could seek guidance from some of you.

class zzz
{
public static void Main()
{
xxx a = new xxx();
a[2] = 20;
System.Console.WriteLine(a[2]);
}
}
class yyy
{
public virtual int this [ int i]
{
get
{
System.Console.WriteLine(“yyy get “ + i);
return 20;
}
set
{
System.Console.WriteLine(“yyy set “ + value + “ “ + i);
}
}
}
class xxx : yyy
{
public override int this [ int i]
{
get
{
int p = base[i];
System.Console.WriteLine(“xxx get “ + i + “ “ + p);
return 200;
}
set
{
System.Console.WriteLine(“xxx set “ + value + “ “ + i);
base[i] = value;
}
}
}

Output obtained:
xxx set 20 2
yyy set 20 2
yyy get 2
xxx get 2 20
200

why is control in set property executing base class code?
Once it goes to base class seeing virtual keyword it should search fr the override
Keyword and come back and again execute the derived class code know?
It happened first time when we used a[2] = 20. How did the flow get changed
when used base in set{ } property??

Thanks in advance.

why is control in set property executing base class code?

You told it to do so by calling base
When a method or indexer in this case is marked virtual it can be overridden it doesn't have to be overridden.
Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.