Click here to Skip to main content
16,020,305 members
Home / Discussions / C#
   

C#

 
AnswerRe: Making Serial Port Visible Pin
Big Daddy Farang30-Oct-12 12:05
Big Daddy Farang30-Oct-12 12:05 
GeneralRe: Making Serial Port Visible Pin
C-P-User-330-Oct-12 12:33
C-P-User-330-Oct-12 12:33 
GeneralRe: Making Serial Port Visible Pin
C-P-User-330-Oct-12 13:09
C-P-User-330-Oct-12 13:09 
GeneralRe: Making Serial Port Visible Pin
Big Daddy Farang30-Oct-12 13:42
Big Daddy Farang30-Oct-12 13:42 
GeneralRe: Making Serial Port Visible Pin
C-P-User-331-Oct-12 4:43
C-P-User-331-Oct-12 4:43 
GeneralRe: Making Serial Port Visible Pin
Pete O'Hanlon31-Oct-12 5:02
mvePete O'Hanlon31-Oct-12 5:02 
GeneralRe: Making Serial Port Visible Pin
C-P-User-32-Nov-12 6:47
C-P-User-32-Nov-12 6:47 
GeneralRe: Making Serial Port Visible Pin
Big Daddy Farang31-Oct-12 5:38
Big Daddy Farang31-Oct-12 5:38 
Let me start with the meanings. As Pete said, private variables or functions can only be used from within the class. Public variables or functions can be used from outside the class. For example, from another class such as your main form you could do the following.

C#
Device device = new Device("COM1");
device.Connect();

because the constructor and Connect() are public. If you're interested in the device's response to connect command you'd want to see LastResponse. If you try
C#
string connectResponse = device.LastRepsonse;

that's not allowed because LastRepsonse is private. You could however write
C#
string connectResponse = device.GetLastResponse();

because that function is public.

What you want private and pubic is up to you, but basically data that should not be changed by outsiders should be private. Things that should be available to users of your class need to be public.

When deciding which ask, "Who wants to know?" Things are private by default, but if users should have access to them make them public. If we made Port public, users could close the serial port and the Device object wouldn't know about it, so that should be kept private.

As far as MSDN goes, yes that's a good reference. But it is designed to be a reference more than an instructional work. You might consider visiting your local bookstore (or online of course) and looking at books that teach C# programming. That depends on your learning style, some people can do fine with reference materials. Given your background you might do well with just reference materials.
BDF

I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be.
-- BillWoodruff

GeneralRe: Making Serial Port Visible Pin
C-P-User-331-Oct-12 6:56
C-P-User-331-Oct-12 6:56 
GeneralRe: Making Serial Port Visible Pin
C-P-User-331-Oct-12 7:02
C-P-User-331-Oct-12 7:02 
GeneralRe: Making Serial Port Visible Pin
David Knechtges31-Oct-12 7:16
David Knechtges31-Oct-12 7:16 
GeneralRe: Making Serial Port Visible Pin
C-P-User-331-Oct-12 7:39
C-P-User-331-Oct-12 7:39 
GeneralRe: Making Serial Port Visible Pin
Big Daddy Farang31-Oct-12 8:26
Big Daddy Farang31-Oct-12 8:26 
GeneralRe: Making Serial Port Visible Pin
C-P-User-32-Nov-12 7:52
C-P-User-32-Nov-12 7:52 
GeneralRe: Making Serial Port Visible Pin
C-P-User-331-Oct-12 8:09
C-P-User-331-Oct-12 8:09 
GeneralRe: Making Serial Port Visible Pin
Big Daddy Farang31-Oct-12 8:37
Big Daddy Farang31-Oct-12 8:37 
GeneralRe: Making Serial Port Visible Pin
C-P-User-331-Oct-12 10:29
C-P-User-331-Oct-12 10:29 
GeneralRe: Making Serial Port Visible Pin
C-P-User-32-Nov-12 6:58
C-P-User-32-Nov-12 6:58 
QuestionC# acess user roles Pin
classy_dog30-Oct-12 9:16
classy_dog30-Oct-12 9:16 
AnswerRe: C# acess user roles Pin
Pete O'Hanlon30-Oct-12 10:29
mvePete O'Hanlon30-Oct-12 10:29 
QuestionWPF - beginner Pin
Nitin S30-Oct-12 1:14
Nitin S30-Oct-12 1:14 
AnswerRe: WPF - beginner Pin
V.30-Oct-12 1:22
professionalV.30-Oct-12 1:22 
AnswerRe: WPF - beginner Pin
Abhinav S30-Oct-12 6:31
Abhinav S30-Oct-12 6:31 
Question"Attempted to read or write protected memory." why am i getting this exception. Pin
Member 943048330-Oct-12 0:37
Member 943048330-Oct-12 0:37 
AnswerRe: "Attempted to read or write protected memory." why am i getting this exception. Pin
Richard MacCutchan30-Oct-12 0:49
mveRichard MacCutchan30-Oct-12 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.