C# enum

C

Coder Coder

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
 
1

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;
}
}
 
I

Ignacio Machin

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top