Return string + enum?

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

    #1

    Return string + enum?

    Hello

    I was wondering if it's possible to return both a string and an enum value?
    both "I have a caddilac" and CADDILAC? as an example..

    if so, could you guys show me?

    TIA
    /Lasse


  • Joe Mayo

    #2
    Re: Return string + enum?

    "Lasse Edsvik" <lasse@nospam.c om> wrote in message
    news:OGRdch3hDH A.1368@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hello
    >
    > I was wondering if it's possible to return both a string and an enum[/color]
    value?[color=blue]
    > both "I have a caddilac" and CADDILAC? as an example..[/color]


    Hi /Lasse,

    Here is one way (pseudo code - I didn't compile this):

    public string MyMethod(out MyEnumType myEnum)
    {
    // do method stuff
    myEnum = MyEnumType.CADD ILAC;
    return "I have a caddilac";
    }

    Call it like this:

    MyEnumType anEnum;

    string myString = MyMethod(out anEnum);

    Console.WriteLi ne("Enum: {0}, String: {1}", anEnum, myString);

    Other possibilities include creating a struct with the enum and string type
    and returning the struct, returning an enum from the method and making the
    string an out parameter, or making both the enum and the string out
    parameters.

    Joe
    --
    Learn C# with step-by-step tutorials and practical examples. Start your first program, explore lists and parsing, and understand how .NET runs your code.



    Comment

    • Lasse Edsvik

      #3
      Re: Return string + enum?

      Joe,

      ok, thanks for helping :) i'll try it out later.

      /Lasse


      "Joe Mayo" <jmayo@ddiieess ppaammeerrssddi iee.com> wrote in message
      news:eXztDQ4hDH A.1692@TK2MSFTN GP10.phx.gbl...[color=blue]
      > "Lasse Edsvik" <lasse@nospam.c om> wrote in message
      > news:OGRdch3hDH A.1368@TK2MSFTN GP12.phx.gbl...[color=green]
      > > Hello
      > >
      > > I was wondering if it's possible to return both a string and an enum[/color]
      > value?[color=green]
      > > both "I have a caddilac" and CADDILAC? as an example..[/color]
      >
      >
      > Hi /Lasse,
      >
      > Here is one way (pseudo code - I didn't compile this):
      >
      > public string MyMethod(out MyEnumType myEnum)
      > {
      > // do method stuff
      > myEnum = MyEnumType.CADD ILAC;
      > return "I have a caddilac";
      > }
      >
      > Call it like this:
      >
      > MyEnumType anEnum;
      >
      > string myString = MyMethod(out anEnum);
      >
      > Console.WriteLi ne("Enum: {0}, String: {1}", anEnum, myString);
      >
      > Other possibilities include creating a struct with the enum and string[/color]
      type[color=blue]
      > and returning the struct, returning an enum from the method and making the
      > string an out parameter, or making both the enum and the string out
      > parameters.
      >
      > Joe
      > --
      > http://www.csharp-station.com
      >
      >[/color]


      Comment

      Working...