Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Private/Public

Private/Public

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wackatronic
    wrote on last edited by
    #1

    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!

    E H 2 Replies Last reply
    0
    • W Wackatronic

      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!

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • W Wackatronic

        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!

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups