0
我有這個需要識別具有模式符號的產品列表。到目前爲止,下面是我用來識別它們的代碼。不幸的是,當我調試程序時,它不識別模式。識別產品名稱中是否存在符號
string[] patterns = new string[] { "." ,",", ";", "'", "`", ":", "/", "\\", "*", "|" ,"(", ")","[", "]", "{", "}", "<", ">" };
List<Product> products = new List<Product>
{
new Product { ID = 1, Name = "Jenny's Product", Price = 10 },
new Product { ID = 2, Name = "Brunus C.O.", Price = 10 },
new Product { ID = 3, Name = "GreenCross", Price = 10 },
};
foreach (var item in products)
{
if (patterns.Contains(item.Name))
{
Console.WriteLine(item.Name);
}
}
Console.ReadLine();
謝謝!你幫了我 – Chris 2015-04-06 06:03:10