将列表转换为字符串数组
我有这些物体
Hi,
I have these objects
public class OutputField
{
public string[] inputFieldValue;
}
public class OutputGroups
{
public OutputField input1 = new OutputField();
public OutputField input2= new OutputField();
}
和带有2个复选框的按钮.
and a button with 2 checkboxes.
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);
}
}
}
当我选中checkbox1时,来自strInput1的所有字符串值都将添加到_OutputToList.Add(_1Output).如果我选中2个框,则来自strInput1和strInput2的字符串值将添加到
我该如何放置List< outputgroups>中的所有字符串? _OutputToList =新列表< outputgroups>()
到此字符串数组
string [] allOutput = {??????????};
谢谢,
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,
创建System.Collections.Generic.List<string></string>
的实例,将所有字符串一一添加,然后将string[]
作为System.Collections.Generic.List<string>.ToArray()</string>
返回. >
或者,如果预先知道字符串数组的长度(假设它是int count = _OutputToList.Count
),则将其全部直接输出到字符串数组:
Create an instance ofSystem.Collections.Generic.List<string></string>
, add all strings one by one to it, and then returnstring[]
asSystem.Collections.Generic.List<string>.ToArray()</string>
.
Alternatively, if the length of the string array is known in advance (let''s say, it isint count = _OutputToList.Count
), output it all directly to the string array:
string[] stringArray = new string[count];
for (int index = 0; index < count; ++index)
// copy elements as requred ...
保持简单,我建议. ;-)
Keep it simple, I would advise. ;-)