• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1218
  • Last Modified:

Method Parameters. Enumeration?

This should be an easy one.  I have a class method, and I want to limit a parameter to one of two values.  Here's what I want:

Method TransferSpreadsheet(TransferType x);

When a programmer tries to call the TransferSpreadsheet method, and they are prompted to enter the TransferType parameter, I want the only two choices to be "Import", or "Export".  

Do I need an enumeration for this?  Can someone walk me through the steps?

Thanks,

ssteeves
0
ssteeves
Asked:
ssteeves
1 Solution
 
gena17Commented:
Hi, ssteeves.

I think you can use or enumeration or boolean type for this.
Boolean is simple - just pass TRUE or FALSE to the method.

Enumeration is simple too:
public enum TransferType
{
      Import,
      Export,
};

void TransferSpreadsheet(TransferType x)
{
  switch (x)
  {
    case TransferType.Import:
      // do some stuff
      break;
    case TransferType.Export:
      // do some stuff
      break;
  }
}

Hope this helps,

Gena
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now