I have an array of some types
private string[] linkTypes = {
"dog",
"cat",
// and so on ..
};
Yes, I could use an enum
but in this case it has to be an array of
strings.
So now I have a List of objects called "LinkElement"
private List<LinkElement> links = new List<LinkElement>();
and these objects have a string property called "Type"
string linkType = links[index].Type;
If linkTypes contains the elements "dog" and "cat", my links can only have "dog" or "cat" as their type.
I want to sort the list "links" by the order of linkTypes.
Means the lists order contains the links with having the type "dog" first and after that the links with the type "cat" come up.
List<LinkElement> sortedLinks = ; // sort links
for (int i = 0; i < sortedLinks.Count; i++)
{
LinkElement currentLink = sortedLinks[i];
Console.WriteLine(currentLink.Type);
}
// Write down dogs first, cats after
Can someone help me out?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…