나는이 T 물건을 아직 정말로 이해하지 못한다. 난 내가 제대로 변환 할 수 없습니다이기 때문에 아래의이 행이 실패방법을 IEnumerable <IEnumerable을 <T>>를 변환 <string>을 나열하려면?
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 };
}
}
목록에 결과 아래 변환해야합니다. 난 당신이 정신적으로 T
string
로 교체 할 수 있습니다, lstShuffle
구현 IEnumerable<string>
때문에 문자열 목록 중 하나
lstShuffle = GetPermutations(lstShuffle).Select(pr => pr.ToString()).ToList();
,하지만 당신은 당신의 코드가 무엇을 이해합니까? – gunr2171
내가 코드를 작성하지 않았으므로 GetPermutations 파트를 이해하지 못합니다. 그것이 내가 묻는 이유입니다. D @ gunr2171 – MonsterMMORPG