Solved

replace or alternative of enum or enumeration

Posted on 2004-09-16
2
286 Views
Last Modified: 2010-04-15
I wanna know how to make a similar structure in c# as the C++ enum. I want to make a program that passes keystrokes/values resulting from t he keystrokes to another class. Actually I'm moving a visual object.

The class I'm using right now has 6 defined variables, and 6 if-statements and 6 IsMovingLeft get/set functions. Something like:
private bool left = false;
if(left){ x=x-1; };
public bool IsMovingLeft
{  get{ return left;}
  set{ left = value; } } six times

Question: how to make anything like this in c#:

// enum.cpp : Defines the entry point for the console application.
#include "stdafx.h"

enum Keystr {UP, DOWN, LEFT, RIGHT, FRONT, BACK};

class EnumClass
{
public:
                void Select(Keystr key)
      {
            switch(key)
            {
            case UP:
                  moveUp();
                  break;
            case DOWN:
                  moveDown();
                  break;
            case LEFT:
                  moveLeft();
                  break;
            case RIGHT:
                            moveRight);
                  break;
            default:
                  break;
            };
      }
      Keystr key;
};


int main(int argc, char* argv[])
{
      EnumClass theClass;

      theClass.key = UP;
      theClass.Select(theClass.key);

      printf("Hello World!\n");
      return 0;
}
0
Comment
Question by:DaFou
2 Comments
 
LVL 9

Accepted Solution

by:
tinchos earned 500 total points
ID: 12077411
Hi

you would do it just the same

enum Keystr {UP, DOWN, LEFT, RIGHT, FRONT, BACK};

class EnumClass
{
     public void Select( Keystr key )
     {
          switch( key )
          {
          case Keystr.UP:
               moveUp();
               break;
          case Keystr.DOWN:
               moveDown();
               break;
          case Keystr.LEFT:
               moveLeft();
               break;
          case Keystr.RIGHT:
                          moveRight);
               break;
          default:
               break;
          };
     }
     Keystr key;
};

Hope this helps

Tincho
0
 
LVL 2

Author Comment

by:DaFou
ID: 12077661
Gee, thanks I feel like a newbie now. ;)

tyvm
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question