开发者

How does Microsoft implement automated properties without "set"? (c#)

开发者 https://www.devze.com 2023-03-14 08:51 出处:网络
As I understand开发者_如何学JAVA, when using automated properties, one must write both set and get methods.

As I understand开发者_如何学JAVA, when using automated properties, one must write both set and get methods. However, when I look at Microsoft's System.Exception, there are some properties that clearly does not follow this demand, for instance: http://msdn.microsoft.com/en-us/library/system.exception.innerexception.aspx.

Can someone please explain me how can this be?


When using an automatic property, one never writes set and get methods. The compiler provides both for you.

If you see a property without a set, or without a get, it was defined the long way, and not an automatic property.

The fact that the backing property is a legal C# name, and not a compiler-reserved name, is another clue that you're looking at a manual property. So is the fact that this property has been around since long before automatic properties were implemented.


Sorry?

What about "no public set"?

Can be.... protected or private and thus be filtered in the documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消