C# enum

  • Thread starter Thread starter Coder Coder
  • Start date Start date
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
 
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;
}
}
 
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,
 
Back
Top