Kann nicht implizit konvertiert Typ 'System.Sammlungen.Generisches.List<int>' zu 'string'

Empfangen die Fehlermeldung:

CS0029: kann Nicht implizit konvertiert Typ 'System.Sammlungen.Generisches.Liste' zu 'string'

Nicht sicher, wie Sie Sie zu beheben.

Abschnitt, gebe mir Mühe ist:

string qty = new List<int>();
foreach (var item in HttpContext.Current.Request.Form.GetValues("quantity_input"))
{
    qty.Add(int.Parse(item));
}

Vollständige code ist:

CartItemCollection items = new CartItemCollection();
Cart cart = Core.GetCartObject();
string skus = "";
string debugStr = "";
Product product = null;
string qty = new List<int>();
foreach (var item in HttpContext.Current.Request.Form.GetValues("quantity_input"))
{
    qty.Add(int.Parse(item));
}
try
{
string[] productNumbers = HttpContext.Current.Request.Form.GetValues("ProductNumber");
foreach (string productNumber in productNumbers)
{
debugStr = debugStr + "-p=" + productNumber;
if(!string.IsNullOrEmpty(productNumber.Trim()) && !productNumber.StartsWith("Enter Product #"))
{
try
{   //redirect if no product found 
product = Core.GetProductObjectByProductNumber(productNumber);
}
catch (Exception e)
{
debugStr = debugStr + "-e=noproductfound";
continue; //do nothing, process the next user input
}
//check if we have a valid product object, allow virtual and other type(s) for adding directly to cart which may need special handling
if(product != null)
{
debugStr = debugStr + "-t=" + product.ProductTypeName;
if(!product.ProductTypeName.Equals("NORMAL"))
{
//assume VIRTUAL (or other type) and redirect for selecting child/group products or other special handling
form.Redirect("product.aspx?p=" + product.ProductNumber);
}
else
{
debugStr = debugStr + "-a=noattributesadd";
CartItem item = new CartItem(context);
item.ProductId = product.ProductId;
item.Quantity = qty;  
items.Add(item);
}
skus = skus + ";" + productNumber;
product = null;  //reset the product object in case the next product number submitted is invalid
}  //product not null
}  //sanity check for empty or default data
}  //iterate on each product submitted
cart.AddItems(items);
form.Redirect("cart.aspx?skus=" + skus);
}
catch (Exception e)
{
form.AddError("*** ProductNumber provided was not found ***");
form.Redirect("quickorder.aspx?qo=2&e=" + e.Message);
return;
}
  • Was ist das: string qty = new List<int>(); ?
  • List<int> qty = new List<int>();
  • Ja, tut mir Leid, dass; ich erbte Sie den code in diesem Zustand 🙁
  • string qty = new List<int>(); Sie versuchen, fügen Sie ein IPad, Iphone Tasche nicht, sehen Sie das?
  • Hier ein Tipp: Lesen Sie den Fehler.
  • Wenn Sie var qty = new List<int>(); den Mauszeiger über var und feststellen, dass es zeigt, die richtige Art, das ist in diesem Fall: List<T>

InformationsquelleAutor aregowe | 2014-04-02
Schreibe einen Kommentar