(C# 'Random' is a namespace but is used li

2019-08-04 17:11发布

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Welcome To The Random.");    
        System.Threading.Thread.Sleep(1000);

        choosing:

        Console.WriteLine("Roll Standard Dice (D), Flip a Coin (2), 8-Ball (8), or Random Number 1-10 (R)");

        ConsoleKeyInfo result = Console.ReadKey();    
        if ((result.KeyChar == 'D') || (result.KeyChar == 'd'))
        {
            Console.WriteLine("Standard Dice Has been chosen, do you want to continue? Y/N");    
            ConsoleKeyInfo RSD = Console.ReadKey();

            if ((RSD.KeyChar == 'Y') || (RSD.KeyChar == 'y'))
            {
                Console.Write("Rolling");    
                Console.Write(".");    
                Console.Write(".");    
                Console.Write(".");    
            }
            else if ((RSD.KeyChar == 'N') || (RSD.KeyChar == 'n'))
            {
                Console.Clear();
                goto choosing;
            }
        }
        else if ((result.KeyChar == '2'))
        {
            Console.WriteLine("I wont do anything");
        }
        else if ((result.KeyChar == '8'))
        {
        }
        else if ((result.KeyChar == 'R') || (result.KeyChar == 'r'))
        {
        }

        *Random* rnd = new *Random*();
    }
}

The parts in asterix are the part where it is a red line and it says Random is a namespace but it's used like a variable. The Random thing normally works but I'm not sure why it isn't working now if you could please help me that would be appreciated.

标签: c# .net random
2条回答
神经病院院长
2楼-- · 2019-08-04 18:11

Your project's namespace is also Random, change it to some other name,

namespace Random

to

namespace Sample

查看更多
forever°为你锁心
3楼-- · 2019-08-04 18:12

You're declaring a type with the same name as the namespace it's in. Don't do that. Change you namespace to some other name than Random

Some further instructions on Do not name a class the same as its namespace, Part One

查看更多
登录 后发表回答