Solved

replace or alternative of enum or enumeration

Posted on 2004-09-16
2
280 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now