What are the pros and cons of expression-bodied properties vs straight property declarations? For example, is there any advantage to using;
public string Foo => "Bar"
vs simply
public string Foo = "Bar"
My understanding was the => is used when the value comes from a method, like a lambda function. If the value is a primitive like a string or int, why would anyone use an expression-bodied property for that?
There are quite a few differences between those two lines of code:
refthe firstFoo.public string Foo { get; } = "Bar";which would also be initialized once and then return the same value).public readonly string Foo = "Bar";or even betterpublic static readonly string Foo = "Bar";