Reputation: 479
I want to be able to allow only certain values to a custom object method. The first example that came to mind to illustrate the point is the VB msgbox and the specific values that you use for which set of buttons you could choose.
MsgBox("Message", vbYesNo,"title")
How would I be able to do the same in C# with a custom object?
The method will search a particular area based on the value sent.
object.method(SearchArea1);
object.method(SearchArea2);
I want to be able just type SearchArea1 or SearchArea2 (not as strings) just like you would use vbYesNo, vbCancel.
Does that make sense at all?
Upvotes: 0
Views: 76
Reputation: 68400
You could define an enum
and then use it as parameter for method
public enum SearchArea
{
SearchArea1,
SearchArea2
}
public void method(SearchArea searchArea)
{
switch (searchArea)
{
case SearchArea.SearchArea1:
// your logic for SearchArea1
break;
case SearchArea.SearchArea2:
// your logic for SearchArea2
break;
default:
throw new ArgumentException("Logic not implemented for provided search area");
}
}
Upvotes: 3