c# - 遍历列表并检查内容?
问题描述
我正在尝试设置一个简单的命令,用于将所有调用者输入到 .txt 文件中,除了我想循环遍历列表并检查没有人试图输入超过一次的部分之外,一切都运行良好,它不会对应用程序本身造成任何问题,但它没有做它应该做的事情。
任何帮助将非常感激。
string filePath = Secret.Secrets.fileDestination;
var username = msg.Author.Username;
//ulong
var ID = msg.Author.Id;
string IDout = ID.ToString();
List<string> entries = File.ReadAllLines(filePath).ToList();
if(entries.Contains(IDout))
{
await msg.Channel.SendMessageAsync($"{msg.Author.Mention}, you have already been entered.");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($"Denied entry for {msg.Author.Mention}");
return;
}
entries.Add($"{username}, {ID}");
File.WriteAllLines(filePath, entries);
await msg.Channel.SendMessageAsync($"{msg.Author.Mention} has been entered!");
解决方案
推荐阅读
- mysql - 在mysql中转义印地语字符
- python-3.x - Python的scipy空间KD树比蛮力欧几里得距离慢?
- javascript - 返回数组中的一个单词
- c# - 流代理 ASP.NET CORE 中的实时流
- python - 如何删除 matplotlib_venn 中的数据标签?
- stata - 从变量中随机选择数字
- python - 如何将表格中的信息显示导出到excel django
- cmake - CMake分别为每个对象执行归档程序
- arduino - 即使我在 digitalWrite(ledpin,LOW); 之后添加了延迟,我的 Led 也不会增加其正常运行时间;
- android - 使用套接字将视频从媒体记录器 (Android) 流式传输到 Node Js 服务器