using System;using System.Collections.Generic;publicclassGhost{privatestaticRandom _rnd =newRandom();privatestatic List<String> _colors =newList<String>{"white","yellow","purple","red"};publicStringGetColor(){return _colors[_rnd.Next(_colors.Count)];}}
答案2:
using System;publicclassGhost{privatereadonlystring[] Colors ={"white","yellow","purple","red"};publicstringGetColor(){return Colors[newRandom().Next(0,4)];}}
答案3:
using System;publicclassGhost{privatestaticstring[] colors ={"white","yellow","purple","red"};privatestring color;publicGhost(){
color = colors[newRandom().Next(colors.Length)];}publicstringGetColor(){return color;}}
答案4:
using System;publicclassGhost{privatestring[] array ={"white","yellow","purple","red"};publicstring result ="";Random _random =newRandom();publicGhost(){
result = array[_random.Next(array.Length)];}publicstringGetColor(){return result;}}
答案5:
using System;publicclassGhost{privatestaticreadonlystring[] colors =newstring[]{"white","yellow","purple","red"};privatestring color = colors[newRandom().Next(colors.Length)];publicstringGetColor(){return color;}}
答案6:
using System;publicclassGhost{privatestring color;publicstringGetColor(){return color ??(color =new[]{"white","yellow","purple","red"}[(newRandom()).Next(0,4)]);}}
答案7:
using System;publicclassGhost{privatestaticreadonlystring[] colors =new[]{"white","yellow","purple","red"};privatereadonlystring color;publicGhost(){var random =newRandom();
color = colors[random.Next(4)];}publicstringGetColor(){return color;}}
颜色鬼【难度:0级】:答案1:using System;using System.Collections.Generic;public class Ghost{ private static Random _rnd = new Random(); private static List<String> _colors = new List<String>...