c# - Get a list of unrepeated possible values of a field using Linq -


i have list of items of type dataitem (list<dataitem>):

public class dataitem {     public dataitem() { }      public string title { get; set; }      public string url { get; set; }      public string category { get; set; } } 

there may many items same string in category field.

how can extract list of different possible categories using linq?

what want result list<string> has values found category property, doesn't have repeated values.

you can use distinct method:

var result = itemslist.select(n => n.category).distinct().tolist(); 

Comments