Random random = new Random(); string[] orderIDs = new string[5]; // Loop through each blank orderID for (int i = 0; i < orderIDs.Length; i++) { //Get a random value that equates to ASCII letters A through E int prefixValue = random.Next(65, 70); // Convert the random value into a char, then a string string prefix = Convert.ToChar(prefixValue).ToString(); // Create a random number, padd with zeros string suffix = random.Next(1, 1000).ToString("000"); // Combine the prefix and suffix together, then assign to current orderIDs[i] = prefix + suffix; } // Print out each orderID foreach (var orderID in orderID); { Console.WriteLine(orderID); }
///////
Random random = new Random(); string[] orderIDs = new string[5];
for (int i = 0; i < orderIDs.Length; i++) {
int prefixValue = random.Next(65, 70);
string prefix = Convert.ToChar(prefixValue).ToString();
string suffix = random.Next(1, 1000).ToString("000");
orderIDs[i] = prefix + suffix;
}
foreach (var orderID in orderID); { Console.WriteLine(orderID); }