tags:

views:

73

answers:

1

Does anybody know why the Console.In, Console.Out and Console.Error properties are read only? One would probably assume because Microsoft didn't intend on having anybody change them, but the framework includes related Console.SetIn(), Console.SetOut() and Console.SetError() methods.

Was there a valid reason for this or just a silly mistake?

+1  A: 

Complete guess, but it could be because the Set* methods have the HostProtectionAttribute applied to them. I don't know offhand whether you can apply an attribute just to the setter part of a property. It's certainly something I've never had to do, and in fact HostProtectionAttribute itself can't be applied to a property by the looks of it.

Jon Skeet
That sounds like a logical answer, to me. Stupid question, however. Couldn't they have applied the attribute to a private method that the property called? Or would that not work?
senfo
If they'd applied the attribute to the private method, it wouldn't be advertised in the docs in nearly as clear a way - and there may be other significance in terms of *knowing* what you're calling. (I'm not sufficiently knowledgeable about HostProtection to say for sure.)
Jon Skeet