您需要显示字典的键,字典是一个数据库,其中服务键以字符串的形式存储,其值是存储登录名和密码的列表。显示时,服务左侧应该有一个序列号(以便用户稍后可以获取密码并通过号码登录),但由于某种原因到处都显示序列号 1 如何解决此问题?提前致谢!
static void Main(string[] args){
Dictionary<string, List<string>> dataBase = new Dictionary<string, List<string>>();
InsertInToDict(dataBase, "Steam", "Alex2004", "qwert12345");
InsertInToDict(dataBase, "discord", "Adam1337", "12345678");
InsertInToDict(dataBase, "Spotify", "marcl2001", "klsjdhfvb12345");
InsertInToDict(dataBase, "YouTube", "Mark1234", "abcd1234");
foreach (string key in dataBase.Keys)
{
int number = 1;
Console.WriteLine($"{number}-{key}");
number++;
}
static void InsertInToDict(Dictionary<string, List<string>> dict, string servise, string login, string password)
{
List<string> dataList = new List<string>();
dataList.Add(servise);
dataList.Add(password);
dict.Add(servise, dataList);
}
}