By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,671 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,671 IT Pros & Developers. It's quick & easy.

C# enum

P: n/a
Hi,
I have the following:

private enum LineFormat { LEFT_TO_RIGHT, RIGHT_TO_LEFT };
private void DrawLine ( LineFormat )
{
// draw differently depending on the parameter
}

So how do have an enum as a parameter. I know I can put an int
parameter and it will be fine, but I want other people using the
libraries to know that Im expexcting a LineFormat.

- thanks
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
100
Hi Coder,
I don't understand what is the problem:
private void enum DrawLine(LineFormat format)
{
//Or whatever
switch(format)
{
case LineFormat.LEFT_TO_RIGHT:
......
break;
case LineFormat.RIGHT_TO_LEFT:
......
break;
}
}
"Coder Coder" <co*******@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
Hi,
I have the following:

private enum LineFormat {LEFT_TO_RIGHT , RIGHT_TO_LEFT };
private void DrawLine ( LineFormat )
{
// draw differently depending on the parameter
}

So how do have an enum as a parameter. I know I can put an int
parameter and it will be fine, but I want other people using the
libraries to know that Im expexcting a LineFormat.

- thanks

Nov 13 '05 #2

P: n/a
Hi,

private enum LineFormat { LEFT_TO_RIGHT, RIGHT_TO_LEFT };

First you shoudl do it public, otherwise nobody outside will can use it.

Other than that there is no mistery:

//Declaration
// If you declare it as private nobody outside the class can use it
private void DrawLine ( LineFormat lineformat) {
}

//call it like
DrawLine( LineFormat.RIGHT );

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Coder Coder" <co*******@yahoo.com> wrote in message
news:f5**************************@posting.google.c om...
Hi,
I have the following:

private enum LineFormat { LEFT_TO_RIGHT, RIGHT_TO_LEFT };
private void DrawLine ( LineFormat )
{
// draw differently depending on the parameter
}

So how do have an enum as a parameter. I know I can put an int
parameter and it will be fine, but I want other people using the
libraries to know that Im expexcting a LineFormat.

- thanks

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.