Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

C#: Enums and implicit conversions

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
Titeuf
l33t
l33t
User avatar
Posts: 759
Joined: Sat Jun 19, 2004 5:36 pm
Location: Middelkerke, Belgium

C#: Enums and implicit conversions

  • Quote

Post by Titeuf » Tue Feb 01, 2005 8:07 pm

I'm trying to make a program with C# (and mono), but I found the following:

Code: Select all

...
public enum Directions:byte{
    Left = 0,
    Up = 1,
    Right = 2,
    Down = 3,
}
...
switch (Direction) {
            case Directions.Left:
                NewXPos--;
                break;
            case Directions.Up:
                System.Console.WriteLine("up");
                NewYPos--;
                break;
            case Directions.Right:
                NewXPos++;
                break;
            case Directions.Down:
                NewYPos++;
                break;
        }
...
When I try to compile this, I get the following error:

Code: Select all

stratego.cs(46) error CS0029: Cannot convert implicitly from `Directions' to `byte'
I know I can fix this problem by using "case (byte) Directions....", but I find it quiet strange, as in my book about C#, they don't have to convert it specifically.
Anyway to solve this without using (byte) ?
Top
Nori
n00b
n00b
Posts: 32
Joined: Thu Nov 18, 2004 6:15 pm

  • Quote

Post by Nori » Tue Feb 01, 2005 8:41 pm

"Direction" in "switch (Direction)" seems to be type of byte, not type of Directions. with ":byte" you just say how memory is allocated for a Direction, but a member of your enum still is type of Directions, not byte. You cant't comapre byte with Directions even if Directions uses byte internally.
Top
Titeuf
l33t
l33t
User avatar
Posts: 759
Joined: Sat Jun 19, 2004 5:36 pm
Location: Middelkerke, Belgium

  • Quote

Post by Titeuf » Tue Feb 01, 2005 8:45 pm

I see, just changing the type of Direction from byte to Directions fixed it.
thank you for your fast reply :)
Top
Post Reply

3 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic