Accidentally I created a bug in my work. The cause of the bug is a snippet of c# code like
public ClassA{
public string AProperty
{
get
{
return AProperty;
}
set
{
AProperty = value;
}
}
}
You can build that, and running that without any exceptions. But it will create an infinite loop. For example, while setting the AProperty, it always tries to assign the value to its self.
Anyone knows why in C# the compiler will allow this syntax?
Because the C# compiler team didn't decide to make this exact case illegal. Possibly because they didn't consider the benefits of implementing it to be greater than the costs.
It's something that comes up with even the most trivial amount of testing; it's not a very subtle bug, and it's something that developers learn to look for if they get bitten by it a few times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With