C# enum

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Coder Coder

    #1

    C# enum

    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
  • 100

    #2
    Re: C# enum

    Hi Coder,
    I don't understand what is the problem:
    private void enum DrawLine(LineFo rmat format)
    {
    //Or whatever
    switch(format)
    {
    case LineFormat.LEFT _TO_RIGHT:
    ......
    break;
    case LineFormat.RIGH T_TO_LEFT:
    ......
    break;
    }
    }
    "Coder Coder" <coder5811@yaho o.com> wrote in message
    news:f547ce3b.0 307151155.12e02 4a9@posting.goo gle.com...[color=blue]
    > 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[/color]


    Comment

    • Ignacio Machin

      #3
      Re: C# enum

      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.RIGH T );

      Hope this help,

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

      "Coder Coder" <coder5811@yaho o.com> wrote in message
      news:f547ce3b.0 307151155.12e02 4a9@posting.goo gle.com...[color=blue]
      > 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[/color]


      Comment

      Working...