It seems that using the ref keyword can be done, creating references to references.
But according to your description, I feel that using Dictionary<TKey,TValue> Class may be more suitable for your current situation.
Dictionary<int, int> keyValuePairs = new Dictionary<int, int>();
Dictionary<int, int> dict = new Dictionary<int, int>();
keyValuePairs.Add(0,45);
keyValuePairs.Add(1,18);
keyValuePairs.Add(2,7);
keyValuePairs.Add(3,60);
keyValuePairs.Add(4,61);
keyValuePairs.Add(5,10);
keyValuePairs.Add(6,3);
keyValuePairs.Add(7,1);
Random random = new Random();
for (int i = 0; i < 5; i++)
{
var keyValuePair = keyValuePairs.ElementAt(random.Next(0, keyValuePairs.Count));
//To avoid selecting the same element repeatedly.
keyValuePairs.Remove(keyValuePair.Key);
dict.Add(keyValuePair.Key, keyValuePair.Value);
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.