• 10-03-2020, 13:27:11
    #1
    Arkadaşlar gelen verileri aşağıdaki gibi foreach içinde döndürüyorum fakat bunları aşağıdaki örnekte göründüğü şekilde dizi olarak nasıl dönüştürebilirim.

    Benim Kodlarım:
    specType uruntipSpec1 = new specType();
    foreach (Control c in pnlSpecs.Controls)
    {
        trChar.Ceviri = c.Name;
        string SPCName = trChar.FriendlyURLTitle();
        uruntipSpec1.name = c.Name;
        uruntipSpec1.type = "CheckBox";
        uruntipSpec1.value = c.Text;
        uruntipSpec1.required = Equals(c.Tag);
    }
    product.specs = uruntipSpec1;
    Örnek Kodlar:
    specType brandSpec = new specType();
    brandSpec.name = "Marka";
    brandSpec.type = "Combo";
    brandSpec.value = "Adidas";
    brandSpec.required = true;
    ....
    
    specType[] specTypeArray = new specType[10];
    specTypeArray[0] = brandSpec;
    ...
    
    product.specs = specTypeArray;
  • 10-03-2020, 13:36:31
    #2
    polatyener adlı üyeden alıntı: mesajı görüntüle
    Arkadaşlar gelen verileri aşağıdaki gibi foreach içinde döndürüyorum fakat bunları aşağıdaki örnekte göründüğü şekilde dizi olarak nasıl dönüştürebilirim.

    Benim Kodlarım:
    specType uruntipSpec1 = new specType();
    foreach (Control c in pnlSpecs.Controls)
    {
        trChar.Ceviri = c.Name;
        string SPCName = trChar.FriendlyURLTitle();
        uruntipSpec1.name = c.Name;
        uruntipSpec1.type = "CheckBox";
        uruntipSpec1.value = c.Text;
        uruntipSpec1.required = Equals(c.Tag);
    }
    product.specs = uruntipSpec1;
    Örnek Kodlar:
    specType brandSpec = new specType();
    brandSpec.name = "Marka";
    brandSpec.type = "Combo";
    brandSpec.value = "Adidas";
    brandSpec.required = true;
    ....
    
    specType[] specTypeArray = new specType[10];
    specTypeArray[0] = brandSpec;
    ...
    
    product.specs = specTypeArray;
    List<specType> sList = new List<specType>();
    foreach (Control c in pnlSpecs.Controls)
    {
    specType uruntipSpec1 = new specType();
    trChar.Ceviri = c.Name;
    string SPCName = trChar.FriendlyURLTitle();
    uruntipSpec1.name = c.Name;
    uruntipSpec1.type = "CheckBox";
    uruntipSpec1.value = c.Text;
    uruntipSpec1.required = Equals(c.Tag);
    sList.Add(uruntipSpec1);
    }
                product.specs = sList.ToArray();
  • 10-03-2020, 13:38:11
    #3
    Merhaba bir tane class oluşturup onu list e ver sonra list.add diyerek ne ekleyeceksen ekle sonra onu list.toarray(); dersin . Çözemezsen akşam yaz pc ne bağlanıp yaparız
  • 10-03-2020, 16:14:40
    #4
    Aşağıdaki şekilde düzenleme yaptım. Fakat tek veri dönüyor yani son veriyi döndürüyor şu anda

    GittiGidiyor.Product.specType uruntipSpec1 = new specType();
    List<specType> sList = new List<specType>();
    foreach (Control c in pnlSpecs.Controls)
    {
        trChar.Ceviri = c.Name;
        string SPCName = trChar.FriendlyURLTitle();
        uruntipSpec1.name = c.Name;
        uruntipSpec1.type = "CheckBox";
        uruntipSpec1.value = c.Text;
        uruntipSpec1.required = Equals(c.Tag);
        sList.Add(uruntipSpec1);
    }
    
    GittiGidiyor.Product.specType[] specTypeArray1 = sList.ToArray();
                
    foreach (GittiGidiyor.Product.specType spec in specTypeArray1)
    {
        str1 += spec.name + "---" + spec.type + "---" + spec.value + "---" + spec.required + Environment.NewLine;
    }
    label9.Text = str1a;