using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
// 示例字典
var dict = new Dictionary<IntPtr, string>
{
{ new IntPtr(1), "Hello World" },
{ new IntPtr(2), "Goodbye World" },
{ new IntPtr(3), "Sample Text" },
{ new IntPtr(4), "Another Example" }
};
// 要排除的关键字
var keywords = new[] { "World", "Sample" };
// 过滤字典,排除包含关键字的项
var filteredDict = dict.Where(pair => !keywords.Any(keyword => pair.Value.Contains(keyword)))
.ToDictionary(pair => pair.Key, pair => pair.Value);
// 输出过滤后的字典
foreach (var item in filteredDict)
{
Console.WriteLine($"Key: {item.Key}, Value: {item.Value}");
}
}
}
07-31
649