How to generate random color names in C#

后端 未结 15 1820
清酒与你
清酒与你 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:41

    If you wanted to get random color from specific colors list,
    then try below one

    Color[] colors = new[] { Color.Red, Color.Blue, Color.FromArgb(128, 128, 255) };    //Add your favorite colors list
    Random randonGen = new Random();
    Color randomColor = colors[Generator.Next(0, colors.Length)];    //It will choose random color from "colors" array
    

提交回复
热议问题