gpt4 book ai didi

c# - ienumerable <字符串>到列表<字符串>

转载 作者:行者123 更新时间:2023-12-02 10:49:28 31 4
gpt4 key购买 nike

我有以下代码片段

        string[] lines = objects.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);  
//convert the array into a list for easier comparison
List<string> StringtoList = lines.OfType<string>().ToList();

//get the database list here
List<string> sensitiveApps = testConnection.SelectSensitive();

//compare the 2 lists to get the difference
List<string> except = sensitiveApps.Except(StringtoList,StringComparer.OrdinalIgnoreCase);

但是,我不断收到上述错误,有人能指出我正确的方向吗?

最佳答案

我猜最后一行抛出异常。尝试更改:

List<string> except = sensitiveApps.Except(StringtoList,StringComparer.OrdinalIgnoreCase);

至:
List<string> except = sensitiveApps.Except(StringtoList,StringComparer.OrdinalIgnoreCase).ToList();

发生此异常是因为 Except将返回 IEnumerable<string>

关于c# - ienumerable <字符串>到列表<字符串>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14427447/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com