Solved

replace or alternative of enum or enumeration

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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