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
-
Is this a compilation or run-time error? IOW, if you put a .Dump in the first line of Main(), does it execute?
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. -
You can get this error if you have something wrong in your additional namespace imports.
eg
System.IO.
(note the . at the end of the name)
