【发布时间】:2013-06-06 02:05:21
【问题描述】:
我还真不明白这个T的东西。我需要将以下结果转换为列表
private void generateKeywords_Click(object sender, RoutedEventArgs e)
{
string srText = new TextRange(
txthtmlsource.Document.ContentStart,
txthtmlsource.Document.ContentEnd).Text;
List<string> lstShuffle = srText.Split(' ')
.Select(p => p.ToString().Trim().Replace("\r\n", ""))
.ToList<string>();
lstShuffle = GetPermutations(lstShuffle)
.Select(pr => pr.ToString())
.ToList();
}
public static IEnumerable<IEnumerable<T>> GetPermutations<T>(
IEnumerable<T> items)
{
if (items.Count() > 1)
{
return items
.SelectMany(
item => GetPermutations(items.Where(i => !i.Equals(item))),
(item, permutation) => new[] { item }.Concat(permutation));
}
else
{
return new[] { items };
}
}
下面这一行失败,因为我无法正确转换。我的意思不是错误,但也不是字符串列表
lstShuffle = GetPermutations(lstShuffle).Select(pr => pr.ToString()).ToList();
【问题讨论】:
-
无意侮辱,但您了解您的代码的作用吗?
-
我不理解 GetPermutations 部分,因为我没有对其进行编码。这就是我问的原因:D @gunr2171
标签: c# linq ienumerable