title: Need dynamic variable names in C# for ebay feeds
body: <p>I need these varaible names to be dynamic.
  To give you an example of what I'm looking at > <a href="https://ebaydts.com/eBayKBDetails?KBid=1742" rel="nofollow noreferrer">https://ebaydts.com/eBayKBDetails?KBid=1742</a></p>
  
  <p>Now in the above link, it has some code for variaitons.</p>
  
  <pre><code>    //Specify Variations
      VariationTypeCollection VarCol = new VariationTypeCollection();
  
      //Variation 1 - Black S
      VariationType var1 = new VariationType();
      var1.SKU = "VAR1";
      var1.Quantity = 10;
      var1.StartPrice = new AmountType();
      var1.StartPrice.currencyID = CurrencyCodeType.AUD;
      var1.StartPrice.Value = 35;
      var1.VariationSpecifics = new NameValueListTypeCollection();
  
      NameValueListType Var1Spec1   = new NameValueListType();
      StringCollection Var1Spec1Valuecoll  = new StringCollection();
  
      Var1Spec1.Name = "Colour";
      Var1Spec1Valuecoll.Add("Black");
      Var1Spec1.Value = Var1Spec1Valuecoll;
  
      var1.VariationSpecifics.Add(Var1Spec1);
  
      NameValueListType Var1Spec2 = new NameValueListType();
      StringCollection Var1Spec2Valuecoll = new StringCollection();
  
      Var1Spec2.Name = "Size";
      Var1Spec2Valuecoll.Add("S");
      Var1Spec2.Value = Var1Spec2Valuecoll;
  
      var1.VariationSpecifics.Add(Var1Spec2);
  
      VarCol.Add(var1);
  
      //Variation 2 - Black L
      VariationType var2 = new VariationType();
      var2.SKU = "VAR2";
      var2.Quantity = 10;
      var2.StartPrice = new AmountType();
      var2.StartPrice.currencyID = CurrencyCodeType.AUD;
      var2.StartPrice.Value = 45;
  
      var2.VariationSpecifics = new NameValueListTypeCollection();
  
      NameValueListType Var2Spec1 = new NameValueListType();
      StringCollection Var2Spec1Valuecoll = new StringCollection();
  
      Var2Spec1.Name = "Colour";
      Var2Spec1Valuecoll.Add("Black");
      Var2Spec1.Value = Var2Spec1Valuecoll;
  
      var2.VariationSpecifics.Add(Var2Spec1);
  
      NameValueListType Var2Spec2 = new NameValueListType();
      StringCollection Var2Spec2Valuecoll = new StringCollection();
  
      Var2Spec2.Name = "Size";
      Var2Spec2Valuecoll.Add("L");
      Var2Spec2.Value = Var2Spec2Valuecoll;
  
      var2.VariationSpecifics.Add(Var2Spec2);
  
      VarCol.Add(var2); 
  </code></pre>
  
  <p>So the code I'm working with I would Like dynamically create the varaible names, because as you can imagine there is no way for me to know how many variations each product has.</p>
  
  <p>Sure i could count the amount of variations, and set up an if else structure </p>
  
  <pre><code>if (count == 1) {
       //some code
  }
  else if (count == 2) {
       //some code
  } 
  </code></pre>
  
  <p>But that doesn't seem like a good solution.</p>
  
  <p>At the moment variables are required to be output inside a for each loop</p>
  
  <p>Here is the code I'm working with:</p>
  
  <pre><code>string UPC = "";
                  string Brand = "";
                  string MPN = "";
  
                  if (!String.IsNullOrEmpty(product.Gtin))
                      UPC = product.Gtin;
  
                  if (!String.IsNullOrEmpty(ebayProduct.EbayProductBrandName))
                      Brand = ebayProduct.EbayProductBrandName;
  
                  if (!String.IsNullOrEmpty(product.ManufacturerPartNumber))
                      MPN = product.ManufacturerPartNumber;
  
                  //create the call object
                  AddFixedPriceItemCall AddFPItemCall = new AddFixedPriceItemCall(context);
  
                  AddFPItemCall.AutoSetItemUUID = true;
  
                  //create an item object and set the properties
                  ItemType item = new ItemType();
  
                  //set the item condition depending on the value from GetCategoryFeatures
                  item.ConditionID = 1000; //new
  
                  //Basic properties of a listing
                  item.Country = CountryCodeType.AU;
                  item.Currency = CurrencyCodeType.AUD;
  
                  //Track item by SKU
                  item.InventoryTrackingMethod = InventoryTrackingMethodCodeType.SKU;
                  item.SKU = ebayProduct.EbayProductSKU;
  
                  if (!String.IsNullOrEmpty(ebayProduct.EbayProductDescription))
                      item.Description = ebayProduct.EbayProductDescription;
                  else
                      item.Description = "This product is brand new.";
  
                  if (!String.IsNullOrEmpty(ebayProduct.EbayProductTitle))
                      item.Title = ebayProduct.EbayProductTitle;
  
                  item.SubTitle = ebayProduct.EbayProductItemSubtitle;
                  item.ListingDuration = "GTC";
  
                  item.ItemSpecifics = new NameValueListTypeCollection();
  
                  NameValueListTypeCollection ItemSpecs = new NameValueListTypeCollection();
  
                  var productSpecAttributes = product.ProductSpecificationAttributes.ToList();
  
                  foreach (var val in productSpecAttributes)
                  {
                      StringCollection valueCol1 = new StringCollection();
                      NameValueListType nv1 = new NameValueListType();
  
                      nv1.Name = val.SpecificationAttributeOption.SpecificationAttribute.Name.Replace(":", "");
                      valueCol1.Add(val.CustomValue);
                      nv1.Value = valueCol1;
  
                      ItemSpecs.Add(nv1);
                  }
  
                  item.ItemSpecifics = ItemSpecs;
  
                  item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection();
                  item.PaymentMethods.Add(BuyerPaymentMethodCodeType.PayPal);
                  item.PayPalEmailAddress = "test@test.com";
                  item.PostalCode = "5000";
  
                  //Specify Shipping Services
                  item.DispatchTimeMax = 3;
                  item.ShippingDetails = new ShippingDetailsType();
                  item.ShippingDetails.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection();
  
                  ShippingServiceOptionsType shipservice1 = new ShippingServiceOptionsType();
                  shipservice1.ShippingService = "AU_Regular";
                  shipservice1.ShippingServicePriority = 1;
                  shipservice1.ShippingServiceCost = new AmountType();
                  shipservice1.ShippingServiceCost.currencyID = CurrencyCodeType.AUD;
                  shipservice1.ShippingServiceCost.Value = 1.0;
  
                  shipservice1.ShippingServiceAdditionalCost = new AmountType();
                  shipservice1.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.AUD;
                  shipservice1.ShippingServiceAdditionalCost.Value = 1.0;
  
                  item.ShippingDetails.ShippingServiceOptions.Add(shipservice1);
  
                  ShippingServiceOptionsType shipservice2 = new ShippingServiceOptionsType();
                  shipservice2.ShippingService = "AU_Express";
                  shipservice2.ShippingServicePriority = 2;
                  shipservice2.ShippingServiceCost = new AmountType();
                  shipservice2.ShippingServiceCost.currencyID = CurrencyCodeType.AUD;
                  shipservice2.ShippingServiceCost.Value = 4.0;
  
                  shipservice2.ShippingServiceAdditionalCost = new AmountType();
                  shipservice2.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.AUD;
                  shipservice2.ShippingServiceAdditionalCost.Value = 1.0;
  
                  item.ShippingDetails.ShippingServiceOptions.Add(shipservice2);
  
                  //Specify Return Policy
                  item.ReturnPolicy = new ReturnPolicyType();
                  item.ReturnPolicy.ReturnsAcceptedOption = "ReturnsAccepted";
  
                  item.StartPrice = new AmountType();
                  item.StartPrice.currencyID = CurrencyCodeType.AUD;
                  item.StartPrice.Value = Double.Parse(ebayProduct.EbayProductPrice.ToString());
  
                  item.PrimaryCategory = new CategoryType();
                  item.PrimaryCategory.CategoryID = ebayProduct.EbayCategoryID;
  
                  item.ProductListingDetails = new ProductListingDetailsType();
                  //Specifying UPC as the product identifier. Other applicable product identifiers
                  //include ISBN, EAN, Brand-MPN.
                  item.ProductListingDetails.UPC = UPC;
  
                  //If multiple product identifiers are specified, eBay uses the first one that
                  //matches a product in eBay's catalog system.
                  item.ProductListingDetails.BrandMPN = new BrandMPNType();
                  item.ProductListingDetails.BrandMPN.Brand = ebayProduct.EbayProductBrandName;
                  item.ProductListingDetails.BrandMPN.MPN = product.ManufacturerPartNumber;
  
                  //If multiple prod matches found, list the item with the 1st product's information
                  item.ProductListingDetails.UseFirstProduct = true;
  
                  //Add pictures
                  item.PictureDetails = new PictureDetailsType();
                  item.PictureDetails.PictureURL = new StringCollection();
  
                  //Specify GalleryType
                  item.PictureDetails.GalleryType = GalleryTypeCodeType.None;
                  item.PictureDetails.GalleryTypeSpecified = true;
                  /*
                   *  Handle Variations
                   */
                  var childProducts = _productService.GetAssociatedProducts(product.Id);
  
                  if (childProducts != null)
                  {
                      //Specify VariationsSpecificsSet
                      item.Variations = new VariationsType();
  
                      item.Variations.VariationSpecificsSet = new NameValueListTypeCollection();
  
                      var colourSpec = productSpecAttributes.FirstOrDefault(
                                              x =&gt; x.SpecificationAttributeOption.SpecificationAttribute.Name == "Colour");
                      var sizeSpec = productSpecAttributes.FirstOrDefault(
                                      x =&gt; x.SpecificationAttributeOption.SpecificationAttribute.Name == "Size");
  
  
                      if (colourSpec != null &amp;&amp; sizeSpec == null)
                      {
                          List&lt;string&gt; colourSpecsList = new List&lt;string&gt;();
  
                          foreach (var cp in childProducts)
                          {
                              var colourSpecs = cp.ProductSpecificationAttributes.FirstOrDefault(
                                                  x =&gt; x.SpecificationAttributeOption.SpecificationAttribute.Name == "Colour");
  
                              colourSpecsList.Add(colourSpecs.SpecificationAttributeOption.Name);
                          }
                          //sizes
                          NameValueListType NVListVS2 = new NameValueListType();
                          NVListVS2.Name = "Colour";
                          StringCollection VSvaluecollection2 = new StringCollection();
                          String[] Colour = colourSpecsList.ToArray();
  
                          VSvaluecollection2.AddRange(Colour);
  
                          NVListVS2.Value = VSvaluecollection2;
                          item.Variations.VariationSpecificsSet.Add(NVListVS2);
                      }
  
                      //Add Variation Specific Pictures
                      item.Variations.Pictures = new PicturesTypeCollection();
  
                      foreach (var cp in childProducts)
                      {
                          //Specify Variations
                          VariationTypeCollection VarCol = new VariationTypeCollection();
  
  
                          PicturesType pic = new PicturesType();
  
                          var specs = cp.ProductSpecificationAttributes.FirstOrDefault(x =&gt; x.SpecificationAttributeOption.SpecificationAttribute.Name == "Colour");
                          var childEbayProduct = _ebayProductService.GetEbayProductById(cp.Id);
  
                          if (!String.IsNullOrEmpty(specs.SpecificationAttributeOption.Name))
                          {
                              VariationType var1 = new VariationType();
                              var1.SKU = cp.RexProductId.ToString();
                              Debug.WriteLine(cp.RexProductId.ToString());
                              var1.Quantity = cp.StockQuantity;
  
                              var1.StartPrice = new AmountType();
                              var1.StartPrice.currencyID = CurrencyCodeType.AUD;
                              var1.StartPrice.Value = Double.Parse(cp.Price.ToString());
                              var1.VariationSpecifics = new NameValueListTypeCollection();
  
                              NameValueListType Var1Spec1 = new NameValueListType();
                              StringCollection Var1Spec1Valuecoll = new StringCollection();
  
                              Var1Spec1.Name = "Colour";
                              Var1Spec1Valuecoll.Add(specs.SpecificationAttributeOption.Name);
                              Var1Spec1.Value = Var1Spec1Valuecoll;
  
                              var1.VariationSpecifics.Add(Var1Spec1);
  
                              //pics
                              pic.VariationSpecificName = "Colour";
                              pic.VariationSpecificPictureSet = new VariationSpecificPictureSetTypeCollection();
                              VariationSpecificPictureSetType VarPicSet1 = new VariationSpecificPictureSetType();
                              VarPicSet1.VariationSpecificValue = specs.SpecificationAttributeOption.Name;
                              StringCollection PicURLVarPicSet1 = new StringCollection();
                              PicURLVarPicSet1.Add(childEbayProduct.EbayProductMainImgUrl);
                              VarPicSet1.PictureURL = PicURLVarPicSet1;
  
                              pic.VariationSpecificPictureSet.Add(VarPicSet1);
                              item.Variations.Pictures.Add(pic);
  
                              VarCol.Add(var1);
  
                              item.Variations.Variation = VarCol;
                          }
                      }
                  }
  </code></pre>
  
  <p>Anyone know what I might be able to do here.
  Cheers</p>