[英]how to generate a unique key for 2d array in c#
i need to generate a unique key for a two dimensional array but i will have the same numbers every time but in different position in array example 我需要为二维数组生成唯一键,但是每次都将具有相同的数字,但是数组示例中的位置不同
first array 第一个数组
0 1 2
3 4 5
7 8 6
second time 第二次
1 2 3
4 5 6
7 8 0
and so on 等等
NOTE : my array will have the values from 0 to 8 every time but in different position 注意 :我的数组每次都将具有从0到8的值,但位置不同
If I understood right you need to create unique for each number from 0 to 8 So you can do this by using array, list or more dynamically by using Dictionnary 如果我理解正确,则需要为0到8的每个数字创建唯一的数字,因此您可以使用数组,列表或使用Dictionnary更动态地进行此操作
Using Array: 使用数组:
string[] numbersUnique = new string[] {"zero","one"....."eight"};
Console.WriteLine("The unique key of {0} is {1}", 2, numbersUnique [2]);
Using Dictionary: 使用字典:
Dictionary<int, string> numbers = new Dictionary<int, string>()
{
{0,"zero"},
{1,"one"},
{2,"two"},
{3,"three"},
// .
// .
{8,"eight"}
};
Console.WriteLine("The unique key of {0} is {1}", 2, numbers[2]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.