Reputation: 27
Adding the items in a checkedListBox
:
DirectoryInfo dinfo = new DirectoryInfo(@"D:\\templates");
FileInfo[] Files = dinfo.GetFiles("*.xml");
foreach (FileInfo file in Files)
{
checkedListBox1.Items.Add(file.Name);
}
foreach (string i in checkedListBox1.CheckedItems)
{
string[] array1 = i;
for (int k = 0; k < array1.Length; k++)
{
XmlDocument xdoc1 = new XmlDocument();
xdoc1.Load(array1[k]);
string s1 = array1[k].ToUpper();
int n = s1.IndexOf(array1[k]);
name1 = array1[k].Substring(n);
}
When I'm putting it in an array, with (string[] array1 = i;
)
it's an giving error:
Cannot implicitly convert type 'string' to 'string[]' "
any suggestions?
Upvotes: 1
Views: 2588
Reputation: 48600
string[] array1 = new string[]{i};
DirectoryInfo dinfo = new DirectoryInfo(@"D:\\templates");
FileInfo[] Files = dinfo.GetFiles("*.xml");
Array.ForEach(Files, str => checkedListBox1.Items.Add(str.Name));
foreach (string i in checkedListBox1.CheckedItems)
{
XmlDocument xdoc1 = new XmlDocument();
xdoc1.Load(i);
name1 = i.Substring(i.ToUpper().IndexOf(i));
}
Upvotes: 0
Reputation: 162
You can not do that. You will need to do something like this
string[] array1 = new string[] { i };
You are trying to assign string
to string[]
. Which is not allowed.
Upvotes: 1