How to generate random color names in C#

后端 未结 15 1824
清酒与你
清酒与你 2020-11-29 21:57

I need to generate random color names e.g. \"Red\", \"White\" etc. How can I do it? I am able to generate random color like this:

Random randonGen = new Ran         


        
15条回答
  •  青春惊慌失措
    2020-11-29 22:55

    Take a random value and get from KnownColor enum.

    May be by this way:

    System.Array colorsArray = Enum.GetValues(typeof(KnownColor));
    KnownColor[] allColors = new KnownColor[colorsArray.Length];
    
    Array.Copy(colorsArray, allColors, colorsArray.Length);
    // get a randon position from the allColors and print its name.
    

提交回复
热议问题