struct
-
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!
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; } }
-
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!
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.
-
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; } }
-
-
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.
-
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.
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
-
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!
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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.
-
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.
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
-
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.
Still, pretty pointless. :D
-
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