CS1001 Identifier expected
I have a simple program (included below) that only gives an error "CS1001 Identifier expected". I am not sure what the problem is. Any ideas?
void Main() { var port = new Port(); Console.ReadLine(); } public class Port { Stopwatch Stopwatch { get; set; } SerialPort SerialPort { get; set; } public Port() { Stopwatch = new Stopwatch(); SerialPort = new SerialPort(); SerialPort.PortName = "COM4"; SerialPort.BaudRate = 9600; SerialPort.DataBits = 8; SerialPort.Parity = Parity.None; SerialPort.StopBits = StopBits.One; SerialPort.DataReceived += OnReceivedData; Stopwatch.Start(); SerialPort.Open(); } void OnReceivedData(object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string indata = sp.ReadExisting(); Stopwatch.Stop(); var elapsed = Stopwatch.ElapsedMilliseconds; Stopwatch.Start(); Debug.WriteLine(elapsed.ToString()); } }
Comments
For me, it compiles OK and during execution, it throws an IOException on SerialPort.Open(), which is expected behavior given that I don't have any COM ports.
eg
System.IO.
(note the . at the end of the name)