top | item 45898396

(no title)

frenzcan | 3 months ago

At last, extension properties in C#. I’ve been waiting for these for years.

discuss

order

Lord_Zero|3 months ago

Why is it better than just using a method?

mrcsharp|3 months ago

Think of it in terms of semantics. An object has certain properties that are immediately obvious and available: color, height, width and so on.

Properties in C# are for such values that are immediately available or at least extremely cheap to retrieve or form. Seeing a property tells me that getting the value is a very small op and has no side effects.

A method on the other hand is like asking/telling the object to do something that can take a bit of time and resources to do.

So if the value you are trying to read is expensive to get and isn't immediately available then the method approach works and as a developer I'll avoid making multiple calls to it unless absolutely necessary because the method is also a possible indication that it might change state.