Link to home
Start Free TrialLog in
Avatar of tmajor99
tmajor99

asked on

C# Creating a unique list of rows from a LIST Array

I have an Array called nodeValues which contains a nested set of attributes for each product.  I need some help to identify only the unique set of attributes from this array.  This array contains a nested table for every product like this:

This table look like this:
    [0] nodeurl = Product 123
           Value
                       [0] Attributetitle = Price
                       [1] Attributetitle = Description
                      [2] Attributetitle = Weight
    [1] nodeurl = Product 888
           Value
                       [0] Attributetitle = Price
                       [1] Attributetitle = Description
                      [2] Attributetitle = Weight
   [2] nodeurl = Product 999
        ..............

All I want to is create a unique set of attributes from the nodeurl array.   For example;

                       [0] Attributetitle = Price
                       [1] Attributetitle = Description
                       [2] Attributetitle = Weight

Here is how I started to code for this:

 foreach (var items in nodeValues)
                  {
                      var Filtervalue = items.value.Select(item => item).Distinct().ToArray();
                      foreach (var attributes in Filtervalue)
                      {
                          FilteredAttributes.Add(....)   ---> How can I not add a duplicate attribute row?   Is there a way to prevent from adding the same attribute to this list array or perhaps a better way I get just get the unique attributes from this array without a forloop?
                      }
                  }

Below is the nodevalue class:

public partial class nodeValue : object, System.ComponentModel.INotifyPropertyChanged {
       
        private string nodeURLField;
       
        private value[] valueField;

Below are the list arrays.

List<FilteredValuesOfAttribure> FilteredValueOfProduct = new List<FilteredValuesOfAttribure>();
List<FilteredValuesOfAttribure> FilteredAttributes = new List<FilteredValuesOfAttribure>();

Below is the class:

public class FilteredValuesOfAttribure
    {
        public string attributeURL { get; set; }
        public string attributeTtitle { get; set; }
        public string value1 { get; set; }
        public string id { get; set; }
        public string name { get; set; }
    }
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

?

Unique for me means one of.  Do you mean if the Attributetitle 'price' appears for two products then it is NOT to appear in the list of unique values?  Because according to your example this list of unique values is empty, everything is duplicated in the two products (123 and 888).
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial