我的程序允许服务器将模块发送给客户端,客户端将在加载模块后返回模块信息.服务器存储将客户端信息存储在一个名为‘loadingModules’的列表中.当服务器从客户端接收到该响应时,它将从所述列表中移除指示该模块的加载操作已经完成的信息.
这里的问题是,我目前使用的方法是遍历整个列表并判断两个成员是否相等(模块名称和时间戳).这不仅效率低下,还会使代码看起来很糟糕.I am wondering if there is some way to do it using a hash of those two members to access the modules in perhaps a dictionary instead of what I am currently doing.
public List<ClientModule> LoadingClientModules = new();
public List<ClientModule> LoadedClientModules = new();
private void ClientModuleAdded_Callback(Packet packet)
{
ClientModule f = Utils.ByteArrayToStructure<ClientModule>(packet.Payload, 0);
Utils.Log.Information($"{_ClientInformation.ComputerUser} Loaded {f.ModuleName} TimeDateStamp: {f.TimeDateStamp} Address: {f.Address}");
LoadedClientModules.Add(f);
LoadingClientModules.RemoveAll(i => i.ModuleName == f.ModuleName && i.TimeDateStamp == f.TimeDateStamp);
OnClientModuleLoaded?.Invoke(this, f);
}