SerialPort question

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

Extracted from the C# example in http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx...

public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
<snip>

I would have thought that the last line would need to be:

SerialPort _serialPort = new SerialPort();
 
Jay said:
Extracted from the C# example in
http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx...

public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
<snip>

I would have thought that the last line would need to be:

SerialPort _serialPort = new SerialPort();

I didn't check the link, but probably the _serialPort property is just
declared outside this method.
Something like:

class blabla {
private static SerialPort _serialPort;

public static void Main() {
_serialPort = new SerialPort();
}

private static void AnotherMethod() {
// do something with _serialPort here
}
}

this way you can access the _serialPort property also from outside the main
method.

HTH
Fabrizio
 
OK, that makes sense. Thanks for your help.

Jay

Jay said:
Extracted from the C# example in
http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx...

public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
<snip>

I would have thought that the last line would need to be:

SerialPort _serialPort = new SerialPort();

I didn't check the link, but probably the _serialPort property is just
declared outside this method.
Something like:

class blabla {
private static SerialPort _serialPort;

public static void Main() {
_serialPort = new SerialPort();
}

private static void AnotherMethod() {
// do something with _serialPort here
}
}

this way you can access the _serialPort property also from outside the main
method.

HTH
Fabrizio
 
Back
Top