我需要从字典中获取键/值对。但我不希望它允许重复的键。
Regex template = new Regex(@"\{(?<key>.+?)\}(?<value>[^{}]*)");
IDictionary<string, string> dictionary = template.Matches(MyString)
.Cast<Match>()
.ToDictionary(x => x.Groups["key"].Value, x => x.Groups["value"].Value);
如何返回允许重复键的字典?
dictionary[key]
,这将获取一个类型为IEnumerable<string>
的对象,其中包含您的值。 - Oleks