當前位置:成語大全網 - 新華字典 - unity 中的字典用下標能拿到值嗎

unity 中的字典用下標能拿到值嗎

可以使用 : 字典名.ElementAt ( 角標 ).Value

導入:using System.Linq; 命名空間

例如:

Dictionary<int, string> dic = new Dictionary<int, string>();

dic.Add(5, "5555");

dic.Add(6, "6666");

dic.Add(7, "7777");

dic.Add(8, "8888");

dic.Add(9, "9999");

dic.ElementAt(4).Value; ?打印結果是: 99999

dic.ElementAt(4); ?打印結果是: [9, 99999]