Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am aware that this is probably a stupid simple solution. I have searched but I am trying to study alone and I am quite lost in this project.

I am trying to create a console based project for school that I would like to upgrade to one my wife could use. In a nut shell, I am trying to create the part of a recipe file that would serve as the ingredients of a recipe. The core of my problem is I do not know how to create the array in the MAIN program correctly.

NOTE this is only focussed on my problem area not full schema.
//My basic XML schema is:
<Ingredients>
   <Item>
     <Name>Eggs</Name>
     <Amount>5 Pounds</Amount>
     <Description>scrabled</Description>
   </Item>
   <Item>
     <Name>Eggs</Name>
     <Amount>5 Pounds</Amount>
     <Description>scrabled</Description>
   </Item>
</Ingredients>

//The XSD file shows this 
<xs:element name="Ingredients">
  <xs:complexType>
      <xs:sequence>
          <xs:element maxOccurs="unbounded" name="Item">
              <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Name" type="xs:string" />
                    <xs:element name="Amount" type="xs:string" />
                    <xs:element name="Description" type="xs:string" />
                  </xs:sequence>
             </xs:complexType>
         </xs:element>
     </xs:sequence>
 </xs:complexType>
</xs:element>

/*I know I am doing the XSD to CS conversion with the XSD command line tool reasonably well. I can make this work if I don't include the arrays. But once I try to use them, the main C# code complains that I need to include a type in my declarations.
*/

//This is the code I put in main, 
//after creating the public partial class calls. 

//Trying to create 3 ingredient objects with each object
//Having a .Name .Amount and .Description string items
rcpPage.Ingredients[] = new string[3];
              
rcpPage.Ingredients[0].Name = "eggs";
rcpPage.Ingredients[0].Amount = "50 Pounds";
rcpPage.Ingredients[0].Description = "Chopped Find as frog fur";

rcpPage.Ingredients[1].Name = "Lettuce";
rcpPage.Ingredients[1].Amount = "A Pinch or two";
rcpPage.Ingredients[1].Description = "Frozen like a brick";

rcpPage.Ingredients[2].Name = "Cat Fur";
rcpPage.Ingredients[2].Amount = "About 4 pounds";
rcpPage.Ingredients[2].Description = "Dry very dry";
Posted
Updated 6-Dec-09 9:57am
v5

1 solution

I guess you want to do

rcpPage.Ingredients[] = new stringIngredients[3];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900