Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,

I have these objects

SQL
public class OutputField
   {
       public string[] inputFieldValue;
   }

   public class OutputGroups
   {
       public OutputField input1 = new OutputField();
       public OutputField input2= new OutputField();
      
   }


and a button with 2 checkboxes.
SQL
private void btnSelect_Click(object sender, EventArgs e)
        {
            try
            {
                List<OutputGroups> _OutputToList = new List<OutputGroups>();

                OutputGroups _1Output = new OutputGroups();

                fileName = parameters.directory;
                sheetNumber = cboSelectWorksheet.SelectedIndex + 1;
                string[] strInput1 = { "Input Address", "Input City", "Input State", "Input Zip" };
                string[] strInput2= { "Indicator", "Return" };
               
              
                if (checkbox1.Checked)
                {                 
                    _1Output.input.inputFieldValue = strInput;
                    _OutputToList.Add(_1Output);                   
                }
                if (checkbox2.Checked)
                {
                    _1Output.LACSLink.inputFieldValue = strLACSLink;
                    _OutputToList.Add(_1Output);   
                }

                string[] allOutput = { };
                getData.AppendInputColumns(fileName, sheetNumber, allOutput);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }       
    }


When i check the checkbox1, all string value from strInput1 will be added to _OutputToList.Add(_1Output). If I check 2 boxes, string values from strInput1 and strInput2 will be added to


How Can i put the all string from List<outputgroups> _OutputToList = new List<outputgroups>()
to this string array
string[] allOutput ={??????????};

thanks,
Posted
Comments
Kenneth Haugland 30-Jul-12 13:39pm    
Think you use CopyTo() or ToArray methoid on the list...
Sergey Alexandrovich Kryukov 30-Jul-12 13:51pm    
What's the problem?
--SA

1 solution

Create an instance of System.Collections.Generic.List<string></string>, add all strings one by one to it, and then return string[] as System.Collections.Generic.List<string>.ToArray()</string>.

Alternatively, if the length of the string array is known in advance (let's say, it is int count = _OutputToList.Count), output it all directly to the string array:
C#
string[] stringArray = new string[count];
for (int index = 0; index < count; ++index)
   // copy elements as requred ...


Keep it simple, I would advise. ;-)

—SA
 
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