Не может преобразовать string в char
Hi everybody, i have created a winform application which run Command Prompt Commands but the problems is i am getting an error Like "Cannot Convert string to char" in this line " psi = new ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1)); " Can anybody please help me I also tried psi = new ProcessStartInfo(TextBox1.Text.Split(' ')(0), TextBox1.Text.Split(' ')(1)); then i am getting error like Method Name Expected Please help with this error and how add whitespace in that split.
Что я уже пробовал:
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; public partial class Form1:Form { private ProcessStartInfo psi; private Process cmd; private delegate void InvokeWithString(string text); private void Button1_Click(System.Object sender, System.EventArgs e) { try { cmd.Kill(); } catch (Exception ex) { } TextBox2.Clear(); if (TextBox1.Text.Contains(" ")) { psi = new ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1)); } else { psi = new ProcessStartInfo(TextBox1.Text); } System.Text.Encoding systemencoding = default(System.Text.Encoding); System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage); var _with1 = psi; _with1.UseShellExecute = false; _with1.RedirectStandardError = true; _with1.RedirectStandardOutput = true; _with1.RedirectStandardInput = true; _with1.CreateNoWindow = true; _with1.StandardOutputEncoding = systemencoding; _with1.StandardErrorEncoding = systemencoding; cmd = new Process { StartInfo = psi, EnableRaisingEvents = true }; cmd.ErrorDataReceived += Async_Data_Received; cmd.OutputDataReceived += Async_Data_Received; cmd.Start(); cmd.BeginOutputReadLine(); cmd.BeginErrorReadLine(); } private void Async_Data_Received(object sender, DataReceivedEventArgs e) { this.Invoke(new InvokeWithString(Sync_Output), e.Data); } private void Sync_Output(string text) { TextBox2.AppendText(text + Environment.NewLine); TextBox2.ScrollToCaret(); } }