How to access random item in list?

后端 未结 12 983
滥情空心
滥情空心 2020-11-22 15:20

I have an ArrayList, and I need to be able to click a button and then randomly pick out a string from that list and display it in a messagebox.

How would I go about

12条回答
  •  粉色の甜心
    2020-11-22 15:50

    Why not[2]:

    public static T GetRandom(this List list)
    {
         return list[(int)(DateTime.Now.Ticks%list.Count)];
    }
    

提交回复
热议问题