syntax - In C#, why you can set a property to its self -


this question has answer here:

accidentally created bug in work. cause of bug snippet of c# code

public classa{         public string aproperty         {                         {                 return aproperty;             }             set             {                 aproperty = value;             }         } } 

you can build that, , running without exceptions. create infinite loop. example, while setting aproperty, tries assign value self.

anyone knows why in c# compiler allow syntax?

because c# compiler team didn't decide make exact case illegal. possibly because didn't consider benefits of implementing greater costs.

it's comes trivial amount of testing; it's not subtle bug, , it's developers learn if bitten few times.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -