本文整理汇总了C#中ISet.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# ISet.GroupBy方法的具体用法?C# ISet.GroupBy怎么用?C# ISet.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISet
的用法示例。
在下文中一共展示了ISet.GroupBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WordBreak
public IList<string> WordBreak(string s, ISet<string> wordDict) {
var paths = new List<Tuple<int, string>>[s.Length + 1];
paths[s.Length] = new List<Tuple<int, string>> { Tuple.Create(-1, (string)null) };
var wordDictGroup = wordDict.GroupBy(word => word.Length);
for (var i = s.Length - 1; i >= 0; --i)
{
paths[i] = new List<Tuple<int, string>>();
foreach (var wordGroup in wordDictGroup)
{
var wordLength = wordGroup.Key;
if (i + wordLength <= s.Length && paths[i + wordLength].Count > 0)
{
foreach (var word in wordGroup)
{
if (s.Substring(i, wordLength) == word)
{
paths[i].Add(Tuple.Create(i + wordLength, word));
}
}
}
}
}
return GenerateResults(paths);
}
示例2: WordBreak
public bool WordBreak(string s, ISet<string> wordDict) {
var f = new bool[s.Length + 1];
f[0] = true;
var wordDictGroup = wordDict.GroupBy(word => word.Length);
for (var i = 1; i <= s.Length; ++i)
{
foreach (var wordGroup in wordDictGroup)
{
var wordLength = wordGroup.Key;
if (i >= wordLength && f[i - wordLength])
{
foreach (var word in wordGroup)
{
if (s.Substring(i - wordLength, wordLength) == word)
{
f[i] = true;
break;
}
}
}
}
}
return f[s.Length];
}
示例3: GroupGenericMethodsByType
/// <summary>
/// </summary>
/// <param name="genericMethodSpecializations">
/// </param>
/// <returns>
/// </returns>
private static SortedDictionary<IType, IEnumerable<IMethod>> GroupGenericMethodsByType(
ISet<IMethod> genericMethodSpecializations)
{
// group generic methods by Type
var genericMethodSpecializationsGroupedByType = genericMethodSpecializations.GroupBy(g => g.DeclaringType);
var genericMethodSpecializationsSorted = new SortedDictionary<IType, IEnumerable<IMethod>>();
foreach (var group in genericMethodSpecializationsGroupedByType)
{
genericMethodSpecializationsSorted[@group.Key] = @group;
}
IlReader.GenericMethodSpecializations = genericMethodSpecializationsSorted;
return genericMethodSpecializationsSorted;
}