A simple and very readable solution:
List<string> results = new List<string>();
foreach (var element in array)
{
if(results.Count == 0 || results.Last() != element)
results.Add(element);
}
More Related Contents:
- 2 ways of list making in c# [duplicate]
- Combine elements of a list [closed]
- What is the best way to organize a lot of data which contains multiple conditions?
- How to remove elements from a generic list while iterating over it?
- ArrayList vs List in C#
- List or IList [closed]
- Create an array or List of all dates between two dates [duplicate]
- How do arrays in C# partially implement IList?
- How can I get every nth item from a List?
- How can I add an item to a IEnumerable collection?
- Binding List to DataGridView in WinForm
- List OrderBy Alphabetical Order
- XML Serialize generic list of serializable objects
- Linq select objects in list where exists IN (A,B,C)
- How to initialize a list of strings (List) with many string values
- Converting from IEnumerable to List [duplicate]
- Does Distinct() method keep original ordering of sequence intact?
- Split string, convert ToList() in one line
- When a class is inherited from List, XmlSerializer doesn’t serialize other attributes
- XmlSerializer serialize generic List of interface
- Main: not all code paths return a value
- How can I sort a List by multiple T.attributes?
- C# – elegant way of partitioning a list?
- Easiest way to Rotate a List in c#
- How to Serialize List?
- How to find List has duplicate values in List [duplicate]
- WriteLine with a class
- Selecting unique elements from a List in C#
- Sort one list by another
- Cast Object to Generic List