如何在RichTextBox中插入字符串
本文关键字:插入 字符串 RichTextBox | 更新日期: 2023-09-27 17:59:43
我正在尝试将字符串输入到richtextbox中,尽管我收到了以下错误:
Cannot implicitly convert type 'string[]' to 'string'
代码如下:
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();
}
尝试string.Join
string[] taskNames = st.GetTaskNames();
richTextBox6.Text = string.Join (Environment.NewLine, taskNames);
如您的代码注释所示:
//获取所有任务名称的数组
您正在创建字符串数组
然后尝试将其分配到字符串属性中
这里不可能自动转换
您应该将数组中的所有(少数)字符串连接到一个字符串中,或者只选择一个要分配的元素。
不能将数组添加到变量中。使用前臂。
foreach (string item in taskNames)
richTextBox6.Text += item;