Public field readonly vs get-only property

Are there cases where you need a readonly vs public field get-only auto-implemented property?

public class Foo { public readonly string Hello; public string Hello2 { get; } } 

Both can only be set during the constructor, and both offer read-only access outside the class. I'm a little tired, so maybe something is missing for me.

+8
source share
2 answers

One of the reasons for data binding, -.net implements a binding to properties, but not to public fields.

Some discussions here: Why can't we use public fields to bind data in C #?

+4
source share

To make this property, not a field, means that it can be used on interfaces.

The exact implementation (although the automatic properties do not really have much implementation ...) is also abstracted, so you can base it on a combination of fields in the future without breaking (compiling) the compatibility.

+7
source share

All Articles