Reputation: 25
I am trying to input a string into a richtextbox, although I get the following error:
Cannot implicitly convert type 'string[]' to 'string'
Code as follows:
private void testing_Click(object sender, EventArgs e)
{
// Get a ScheduledTasks object for the computer named "DALLAS"
string machineName = (@"\\" + System.Environment.MachineName);
ScheduledTasks st = new ScheduledTasks(machineName);
// Get an array of all the task names
string[] taskNames = st.GetTaskNames();
richTextBox6.Text = taskNames;
// Dispose the ScheduledTasks object to release COM resources.
st.Dispose();
}
Upvotes: 0
Views: 3133
Reputation: 1804
As your code comments follows:
// Get an array of all the task names
You are creating string array.
Then you try to assign it into the string property.
No autoconversion is possible here.
Your should either join all(few) strings in the array into one string or choose only one element to assign.
Upvotes: 2
Reputation: 1117
You cannot add an array to a variable. Use foreach.
foreach (string item in taskNames)
richTextBox6.Text += item;
Upvotes: 1
Reputation: 27943
Try string.Join
string[] taskNames = st.GetTaskNames();
richTextBox6.Text = string.Join (Environment.NewLine, taskNames);
Upvotes: 3