Solved

replace or alternative of enum or enumeration

Posted on 2004-09-16
2
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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