सबसे पहले, 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