Do we know the exact reasons why is it allowed?
Yes. yield
is only a contextual keyword. It was introduced in C# 2, and the team didn't want to break code which already used yield
as an identifier.
The same is true for other contextual keywords which have been introduced since 1.0, such as partial
. See Eric Lippert's blog post for the complete list.
but still it adds to the confusion and lessen the readability of the code
So don't do that then? There are any number of things you can do to make your code really, really hard to read. You could make all your variable names just underscores:
private int _;
private string __;
// etc
Do you do that? If not, why would you expect people to write confusing code with yield
specifically?