Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

replace or alternative of enum or enumeration

Posted on 2004-09-16
2
Medium Priority
?
293 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
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: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

661 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