Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Private mVariable As struConditions

Public Structure struConditions
  Dim bVisible As Boolean
  Dim sUrl As String
End Structure

Public Property sVariable() As struConditions
       Get
           Return mVariable
       End Get
       Set(ByVal value As struConditions)
           mVariable = value
       End Set
End Property

 

Doesn't let me reset bVisible to True when I call

 

Class.sVariable.bVisible.Equals(True)

 

What am I doing wrong?

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Posted

Equals is a method that checks if the calling objects value is the same as the value passed in as a parameter. Thus you are not actually assigning anything with that line of code. In theory the correct line of code would be

Class.sVariable.bVisible = True;

But this won't work because you cannot assign a value to the child of a value type in this manner. You will either have to change the structure to a class or you will have to create a new instance of the structure with the required fields set and assign sVariable as equal to that.

Anybody looking for a graduate programmer (Midlands, England)?
Posted

Why is it so critical that the thing you have as a struct be a struct? You've used 4 lines of code where you could use 1 if you would just make it a class. What happens if you have to change the value again? That's another extra 3 lines of code.

 

I'm just concerned that

1. You'll make mistakes (because more loc = more potential for bugs)

2. You're making things harder for yourself than they really need to be

Posted
Whilst its true it adds lines of code which can in turn lead to errors, changing the Stucture to a Class could be catastropic on the application in the short term. It is quite likely that elsewhere in their code TheWizardofInt has statements that would function differently if the value type is changed to a reference type.
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...