Skip to content

Enums in c# but i got a lot of errors how can i fix them?

kristof Edelgast

Asked Mar 24, 2010, 2:45 PM EDT2 answers
Share
LinkedInX
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace exampleChess
{
class Program
{

  static void Main(string[] args)
{
Random random1 = new Random();
for (int i = 0; i < 3; i++)
{
enum color { black, white};
enum chess { pawn, knight, bishop, rook, king, queen};
color colors = random1.Next(0, 2);
chess pieces = random1.Next(0, 6);
Console.WriteLine(colors + " " + pieces);
}
}
}
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace exampleChess
    {
        enum color { black, white};
        enum chess { pawn, knight, bishop, rook, king, queen};
        class Program
        {
            static void Main(string[] args)
            {
                Random random1 = new Random();
                for (int i = 0; i < 3; i++)
                {
                    color colors = (color) random1.Next(0, 2);
                    chess pieces = (chess) random1.Next(0, 6);
                    Console.WriteLine(colors + " " + pieces);
                }
            }
        }
    }
    So this is the right code. First of all you need to put enums before you class. Second of all you need to cast the randoms to your enums.
    Good luck.
    0
  • Hirendra Sisodiya
    0
    Wim haes's code is right...........
    0