প্রথমে C#-এ একটি লিস্ট সেট করুন।
var list = new List<string>{ "one","two","three","four" };
এখন এলিমেন্টের কাউন্ট পান এবং র্যান্ডমলি প্রদর্শন করুন।
int index = random.Next(list.Count); Console.WriteLine(list[index]);
উদাহরণ
using System;
using System.Collections.Generic;
namespace Demo {
class Program {
static void Main(string[] args) {
var random = new Random();
var list = new List<string>{ "one","two","three","four"};
int index = random.Next(list.Count);
Console.WriteLine(list[index]);
}
}
}
আউটপুট
three