0

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();

}

3 Answers 3

3

Try string.Join

string[] taskNames = st.GetTaskNames();
richTextBox6.Text = string.Join (Environment.NewLine, taskNames);
2

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.

1

You cannot add an array to a variable. Use foreach.

foreach (string item in taskNames)
            richTextBox6.Text += item;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.