I want to simply call my method like this: collect.clear; instead of, collect.clear();
Well, frankly: you don't get to decide what the language syntax is, and in C#, the syntax for invoking a method is: collect.clear();
.
Basically, you can't do what you want. You could make it a property, but then you'd need to discard the result (so it can choose between get
and set
), i.e. with a property get called clear
, _ = collect.clear;
- frankly I think that's a step back from the ()
. It is also a terrible idea from the basis of unexpected side-effects; most UI elements (including the debugger) and libraries (serializers, etc) think that they can freely evaluate property gets, so it would be very unexpected it reviewing a property had the side effect of clearing the data! Basically, don't do that.
So; embrace the ()
. They express the intent here, for your benefit, the benefit of people reviewing/maintaining it, and for the benefit of the compiler.