Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to define limited selection for function parameter 1

Status
Not open for further replies.

djfrear

Programmer
Jul 11, 2007
83
0
0
GB
Lets say I have a function:

Code:
private void MyFunction(String Action)
{
  //code
}

Now if I wanted "Action" to be a limited list of selections, how would I implement that so it showed up in intellisense?

Thanks in advance, Daniel.
 
You need to have an enum...

public enum Actions { Stop = 0, Start = 1, Continue = 2 };

Then, in your function you will have to put:

private void MyFunction(Actions action)
{
//code
}


This will only allow you to select from one of the selections available in the Actions enum.

Cheers,

G.


Oxigen - Next generation business solutions
-----------------------------
Components/Tools/Forums/Software/Web Services
 
from the microsoft style guide:


Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields.

so Actions would be for not mutually exclusive options which can be 'or'ed together.

so:

Code:
public enum Action { Stop = 0, Start = 1, Continue = 2 };

public enum Actions { KillNow = 1, PreserveOptions = 2, LogError = 4 };


mr s. <;)
 
Thanks for all the help, that will do nicely!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top