为什么调用此函数不会打印任何内容?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
public class Program
{
public static void Main()
{
Dictionary<string, List<string>> cars = new Dictionary <string, List<string>>() {
{"importcar", new List<string>() {"audi", "bmw", "mercedes"}},
{"domesticcar", new List<string>() {"chevy", "mustang"}},
{"truck", new List<string>(){"ford", "gmc", "chevy", "toyota"}}
};
var query = cars.Where(x => x.Value.Contains(" CHEVY", new TrimStringComparer())).ToArray();
for (int i = 0; i < query.Length; i++)
{
cars.Remove(query[i].Key);
}
Console.WriteLine(cars.Count); //Or any other logic you need...
}
}
class TrimStringComparer : IEqualityComparer<String> //Use this instead of StringComparer.InvariantCultureIgnoreCase if you need to Trim() both values in the comparison
{
public bool Equals(string x, string y)
{
return x.Trim().ToLowerInvariant().Equals(y.Trim().ToLowerInvariant());
}
public int GetHashCode(string obj)
{
return obj.GetHashCode();
}
}
答案 0 :(得分:6)
for
已被延迟评估,您的代码中没有任何内容询问以获取for
的结果。试试doseq
:
(defn test-go-loop []
(go (doseq [a (cycle [:a :b :c])]
(println a)
(<! (timeout 1000)))))