Search code examples
c#propertiesis-empty

C# empty property


What's the preferred way to implement IsEmpty statement for your own container-like class?

It could be a simple method bool IsEmpty() or you could have some gettable property IsEmpty / Empty.

I understand it's probably a matter a personal choice, but would you stick to properties or methods in such cases?


Solution

  • The general rule is if it is costly, or has side effects then make it a method. If it just reads a field make it a property.