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. struct

struct

Scheduled Pinned Locked Moved C#
csharpvisual-studio
14 Posts 8 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.
  • H honeyman_can

    forgive me - I'm new to c# public struct lookupOjbect { string fieldvalue; public lookupOjbect (string fieldvalue) { this.fieldvalue = fieldvalue; } } lookupOjbect lookupObjectRow = new lookupOjbect(); When I want to assign a value to this object then 'fieldvalue' doesnt show with intellisense. e.g. lookupObjectRow.fieldvalue - doesnt show!

    W Offline
    W Offline
    wheelerbarry
    wrote on last edited by
    #2

    it is because fieldvalue is private. Try public string fieldvalue though that is not great oop, and most thing use properties to get around that and keep encapulation, e.g. private string fieldvalue; public string FieldValue { set { this.fieldvalue = value; } get { return this.fieldvalue; } }

    H 1 Reply Last reply
    0
    • H honeyman_can

      forgive me - I'm new to c# public struct lookupOjbect { string fieldvalue; public lookupOjbect (string fieldvalue) { this.fieldvalue = fieldvalue; } } lookupOjbect lookupObjectRow = new lookupOjbect(); When I want to assign a value to this object then 'fieldvalue' doesnt show with intellisense. e.g. lookupObjectRow.fieldvalue - doesnt show!

      T Offline
      T Offline
      Tristan Rhodes
      wrote on last edited by
      #3

      The default accessor property for a field in C# is private, therefore it would only be accessible internaly, and not appear on intellisense. Just wack public infront of it.

      1 Reply Last reply
      0
      • W wheelerbarry

        it is because fieldvalue is private. Try public string fieldvalue though that is not great oop, and most thing use properties to get around that and keep encapulation, e.g. private string fieldvalue; public string FieldValue { set { this.fieldvalue = value; } get { return this.fieldvalue; } }

        H Offline
        H Offline
        honeyman_can
        wrote on last edited by
        #4

        -

        T 1 Reply Last reply
        0
        • H honeyman_can

          -

          T Offline
          T Offline
          Tristan Rhodes
          wrote on last edited by
          #5

          Remember that changing the values in a struct type only affect that particular instance as it is a value type. If you are planning on implementing a Get / Set accessor, you may want to think about using a class instead.

          C 1 Reply Last reply
          0
          • T Tristan Rhodes

            Remember that changing the values in a struct type only affect that particular instance as it is a value type. If you are planning on implementing a Get / Set accessor, you may want to think about using a class instead.

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #6

            The Catalyst wrote:

            Remember that changing the values in a struct type only affect that particular instance as it is a value type.

            And so what happens in a class if it doesn't "only affect that particular instance"?

            The Catalyst wrote:

            If you are planning on implementing a Get / Set accessor, you may want to think about using a class instead

            Why would a class be better in this instance? What is wrong with putting Get/Set accessors on a struct?


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            T 1 Reply Last reply
            0
            • H honeyman_can

              forgive me - I'm new to c# public struct lookupOjbect { string fieldvalue; public lookupOjbect (string fieldvalue) { this.fieldvalue = fieldvalue; } } lookupOjbect lookupObjectRow = new lookupOjbect(); When I want to assign a value to this object then 'fieldvalue' doesnt show with intellisense. e.g. lookupObjectRow.fieldvalue - doesnt show!

              E Offline
              E Offline
              Ennis Ray Lynch Jr
              wrote on last edited by
              #7

              public members are a crime keep fieldValue private.

              A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

              L 1 Reply Last reply
              0
              • C Colin Angus Mackay

                The Catalyst wrote:

                Remember that changing the values in a struct type only affect that particular instance as it is a value type.

                And so what happens in a class if it doesn't "only affect that particular instance"?

                The Catalyst wrote:

                If you are planning on implementing a Get / Set accessor, you may want to think about using a class instead

                Why would a class be better in this instance? What is wrong with putting Get/Set accessors on a struct?


                Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                T Offline
                T Offline
                Tristan Rhodes
                wrote on last edited by
                #8

                Colin Angus Mackay wrote:

                And so what happens in a class if it doesn't "only affect that particular instance"?

                It's the old Refference / Value type behavior. I think i worded it badly. Any change made to a class is reflected through all refferences, making changes to a struct only changes the one you are changing in the local context. (Barring special circumstances)

                Colin Angus Mackay wrote:

                Why would a class be better in this instance? What is wrong with putting Get/Set accessors on a struct?

                I've never seen a Get / Set in a struct, at least, not in the standard CLR libraries. Tho i suppose there must be some, i can't imagine a use for them; All the com interop structs use public fields. From what i've seen, everything gets set in the ctor. and accessed through read only properties.

                J 1 Reply Last reply
                0
                • T Tristan Rhodes

                  Colin Angus Mackay wrote:

                  And so what happens in a class if it doesn't "only affect that particular instance"?

                  It's the old Refference / Value type behavior. I think i worded it badly. Any change made to a class is reflected through all refferences, making changes to a struct only changes the one you are changing in the local context. (Barring special circumstances)

                  Colin Angus Mackay wrote:

                  Why would a class be better in this instance? What is wrong with putting Get/Set accessors on a struct?

                  I've never seen a Get / Set in a struct, at least, not in the standard CLR libraries. Tho i suppose there must be some, i can't imagine a use for them; All the com interop structs use public fields. From what i've seen, everything gets set in the ctor. and accessed through read only properties.

                  J Offline
                  J Offline
                  Judah Gabriel Himango
                  wrote on last edited by
                  #9

                  The Catalyst wrote:

                  I've never seen a Get / Set in a struct, at least, not in the standard CLR libraries.

                  Actually, virtually every struct I've seen in the BCL uses properties: Point, Size, Rectangle, to name a few, all expose their data via properties.

                  Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  T 1 Reply Last reply
                  0
                  • J Judah Gabriel Himango

                    The Catalyst wrote:

                    I've never seen a Get / Set in a struct, at least, not in the standard CLR libraries.

                    Actually, virtually every struct I've seen in the BCL uses properties: Point, Size, Rectangle, to name a few, all expose their data via properties.

                    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                    T Offline
                    T Offline
                    Tristan Rhodes
                    wrote on last edited by
                    #10

                    True, but they are all read only. None of them implement a set method, you have to create a new object if you want to use different values.

                    A J 2 Replies Last reply
                    0
                    • T Tristan Rhodes

                      True, but they are all read only. None of them implement a set method, you have to create a new object if you want to use different values.

                      A Offline
                      A Offline
                      Andrew Lygin
                      wrote on last edited by
                      #11

                      The Catalyst wrote:

                      True, but they are all read only. None of them implement a set method

                      That's wrong. Look at the Point.X for example. You can set it.

                      T 1 Reply Last reply
                      0
                      • T Tristan Rhodes

                        True, but they are all read only. None of them implement a set method, you have to create a new object if you want to use different values.

                        J Offline
                        J Offline
                        Judah Gabriel Himango
                        wrote on last edited by
                        #12

                        The Catalyst wrote:

                        True, but they are all read only.

                        Have a look at Rectangle.Width, Height, Size, and others.

                        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                        1 Reply Last reply
                        0
                        • A Andrew Lygin

                          The Catalyst wrote:

                          True, but they are all read only. None of them implement a set method

                          That's wrong. Look at the Point.X for example. You can set it.

                          T Offline
                          T Offline
                          Tristan Rhodes
                          wrote on last edited by
                          #13

                          Still, pretty pointless. :D

                          1 Reply Last reply
                          0
                          • E Ennis Ray Lynch Jr

                            public members are a crime keep fieldValue private.

                            A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #14

                            If a tree drops in the forest... :)

                            **

                            xacc.ide-0.2.0.50 - now with partial MSBuild support!

                            **

                            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