Property or Method ??
I needed a way to pass in a list of ids (that should be selected) to a control and also a way to retrieve the selected values only, so here is what I came up with
Approach 1
public void SetSelectedAuthors(int[] authorsToBeSelected) {}
public int[] GetSelectedAuthors() {}
I would have made this into a property named SelectedAuthorIds of type int[], but a property with array type is not recommended, so I desisted and instead went for a get/set method pair. But I was not happy with the names and removed the Get and Set part and this is what I came up with :-
Approach 2
public void SelectedAuthorIds(int[] authorsToBeSelected) {}
public int[] SelectedAuthorIds() {}
But here, SelectedAuthorIds sounds like data (property) rather than action (method) and I am again tempted to implement it as a property.
Approach 3
If I were to implement it as a property, I would be going the ListView.SelectedIndices property way. ListView.SelectedIndices returns what is basically a collection of ints, and the property would become like this
IntCollection SelectedAuthorIds {get;set;}
Again, there are two problems with this
1) I need a fixed bounds IntCollection object similar to the ListView.SelectedIndexCollection which will have to be coded, then tested, but which maybe reused later.
2) SelectedAuthorIds involves iterating through a CheckedListBox or ListView and individually working with the Checked property of the items. This can be expensive and ideally should be not be called again and again. But a property is by default efficient to be called multiple times, isn't it ? so should this be a method ??
Does this make sense ? implementing IntCollection ? or should I implement Approach 2 or 1 ? due to lack of time, I am currently sticking with Approach 2 but I am curious what others will think of it ? I have read Brad Adams' blog about this many times but still am in a sort of dilemma.