Private/Public
-
I was wondering if you could have a public structure with private/public objects within it? Like in this example
public struct ClientData { public Socket clientSocket; public Thread clientThread; private int clientMonitorID; }
or if you define it as public does object within become public
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat! -
I was wondering if you could have a public structure with private/public objects within it? Like in this example
public struct ClientData { public Socket clientSocket; public Thread clientThread; private int clientMonitorID; }
or if you define it as public does object within become public
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!Yes you can have a public structure with private and public objects in it. The private objects will not be accessible from outside the struct, this can be used if for example you want to pass a value to the constructor of the struct and use it internally (do not want other objects to access it).
public struct ClientData
{
private int clientMonitorID;
public ClientData(int clientMonitorID)
{
this.clientMonitorID = clientMonitorID;
}public int FunctionX() { FunctionX = clientMonitorID + 1 }
}
Edbert P. Sydney, Australia.
-
I was wondering if you could have a public structure with private/public objects within it? Like in this example
public struct ClientData { public Socket clientSocket; public Thread clientThread; private int clientMonitorID; }
or if you define it as public does object within become public
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!Yes, as Elbert said, it is possible. I wanted to add that, like classes, you should actually declare public properties that reflect private fields in your structure. This not only gives you a chance to validate input (always a good idea) but also to invoke delegates if necessary since properties are just getter and/or setter methods. You can still do it with fields, but it's quite a bit more difficult.
Microsoft MVP, Visual C# My Articles