471,595 Members | 2,233 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

SerialPort question

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();
Jan 9 '07 #1
2 1701
"Jay" <nospamwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
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
Jan 9 '07 #2
Jay
OK, that makes sense. Thanks for your help.

Jay

"Fabrizio Romano" <sf*****@zerovolt.comwrote in message
news:45***********************@reader4.news.tin.it ...
"Jay" <nospamwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
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

Jan 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Joshua Moore | last post: by
3 posts views Thread by Eric | last post: by
13 posts views Thread by Jean Paul Mertens | last post: by
6 posts views Thread by Keith Lee | last post: by
10 posts views Thread by sklett | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.