প্রথমত, C# এ একটি তালিকা সেট করুন।
var list = new List<string>{ "one","two","three","four"}; এখন উপাদানগুলির গণনা পান এবং এলোমেলোভাবে প্রদর্শন করুন৷
int index = random.Next(list.Count); Console.WriteLine(list[index]);
C# এ একটি তালিকা থেকে একটি এলোমেলো উপাদান নির্বাচন করতে, নিম্নলিখিত কোডটি চালানোর চেষ্টা করুন −
উদাহরণ
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