LINQ ответ:
table.OrderBy(sentence => sentence.NextID);
Редактировать: Надеюсь, на этот раз я ответил правильно:
class Sentence
{
public int Id;
public int? NextId;
public string Text;
public Sentence(int id, int? nextId, string text)
{
this.Id = id;
this.NextId = nextId;
this.Text = text;
}
}
var Sentences = new [] {
new Sentence(1, 12, "This quick"),
new Sentence(3, 40, "jumps over"),
new Sentence(5, null, "lazy dog."),
new Sentence(12, 3, "brown fox"),
new Sentence(40, 5, "the"),
};
Func<int?, string> GenerateSentence = null;
GenerateSentence = (id) => id.HasValue? Sentences
.Where(s => s.Id == id.Value)
.Select(s => s.Text + " " + GenerateSentence(s.NextId))
.Single() : string.Empty;
Console.WriteLine(GenerateSentence(1));