List<class> Help

inkedGFX

Well-known member
Joined
Feb 2, 2013
Messages
142
Programming Experience
Beginner
I need some help with adding either a string array or list to a List<class>

what I want to do is this:

I am collecting data from a website , on this website there is a header section which has breadcrumb links..I get this data and have it in a HtmlNodeCollection header. from there I would like to add it to my Part class which I create a List<Part> ...my question is , How to add the collection from the header in the constructor of the Part class.....the Part class code is below:

 public class Part
    {
        public List<string> header = new List<string>();
       
        //Properties
        public string Part_Title { get; set; }
        public string Part_Number { get; set; }
        public string List_Price { get; set; }
        public string Our_Price { get; set; }
        public string Prod_Desc { get; set; }
        public string Part_ImageLocation { get; set; }
        public string[] Header { get; set; }
        //Cunstructor with no arguments
        public Part()
        {
            
        }
        //Constructor
        public Part(string parTitle, string partNumber, string listPrice, string ourPrice, string prodDesc, string part_imageLocation,
            string[] _header) [COLOR=#FF0000]<----- Is this correct? if it is, how to add data to it?[/COLOR]
        {
            Part_Title = parTitle;
            Part_Number = partNumber;
            List_Price = listPrice;
            Our_Price = ourPrice;
            Prod_Desc = prodDesc;
            Part_ImageLocation = part_imageLocation;
            [COLOR=#FF0000]how do I add the contents of the HtmlNodeCollection to this string[] header or the List header?[/COLOR]
        }
        public override string ToString()
        {
            return Part_Title + ", " + Part_Number + ", " + List_Price + ", " + Our_Price + ", " + Prod_Desc  + ", " + Part_ImageLocation;
        }
       
        
    }



the code below is how I am adding data to the List<Part>

spider.partList.Add(new Part("Part #" + validCount.ToString() + " " + partTitle, partNumber, listPrice, ourPrice, partDesc, partImageLocation, string[] header));<-[COLOR=#FF0000]--Correct or Not?[/COLOR]


thank you for any help

-InkedGFX
 

tumatauenga

Member
Joined
Aug 30, 2014
Messages
6
Programming Experience
3-5
uhm u've mostly everything u need
/*sample data goes here*/
                List<Part> partList = new List<Part>();
                string[] header={"your","collection"};
                int validCount = 0;
                string partTitle = "partTitle";
                string partNumber = "";
                string listPrice = "0.00";
                string ourPrice = "1.00";
                string partDesc = "some description";
                string partImageLocation = "this should be a valid path, shouldn't it?";
                partList.Add(new Part("Part #" + validCount.ToString() + " " + partTitle, partNumber, listPrice, ourPrice, partDesc, partImageLocation, header));
/* our costum class */
    public class Part
   {
       public List<string> header = new List<string>();
       
       //Properties
       public string Part_Title { get; set; }
       public string Part_Number { get; set; }
       public string List_Price { get; set; }
       public string Our_Price { get; set; }
       public string Prod_Desc { get; set; }
       public string Part_ImageLocation { get; set; }
       public string[] Header { get; set; }
       //Cunstructor with no arguments
       public Part()
       {
           Part_Title = "defaultTitle";
           Part_Number = "defaultPartNumber";
           List_Price = "0.00";
           Our_Price = "0.00";
           Prod_Desc = "";
           Part_ImageLocation = "";
           Header=new string[]{};
       }
       //Constructor
       public Part(string parTitle, string partNumber, string listPrice, string ourPrice, string prodDesc, string part_imageLocation,
           string[] _header) 
       {
           Part_Title = parTitle;
           Part_Number = partNumber;
           List_Price = listPrice;
           Our_Price = ourPrice;
           Prod_Desc = prodDesc;
           Part_ImageLocation = part_imageLocation;
           Header = _header;
       }
       public override string ToString()
       {
           return Part_Title + ", " + Part_Number + ", " + List_Price + ", " + Our_Price + ", " + Prod_Desc  + ", " + Part_ImageLocation;
       }
   }
 
Top Bottom