Return string + enum?

  • Thread starter Thread starter Lasse Edsvik
  • Start date Start date
L

Lasse Edsvik

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
 
Lasse Edsvik said:
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..


Hi /Lasse,

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

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

Call it like this:

MyEnumType anEnum;

string myString = MyMethod(out anEnum);

Console.WriteLine("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
 
Back
Top