• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 898
  • Last Modified:

Expression is a value and therefore cannot be the target of an assignment vb.net

Public Structure _cache
    Public loading As Boolean
End Structure


Public Class Server
    Public _cache_List As New List(Of _cache)()
...

For index As Int16 = 0 To _cache_List.Count - 1
_cache_List(index).loading = false '--> error
Next

"Expression is a value and therefore cannot be the target of an assignment "

what was wrong in the code above?
0
JSW21
Asked:
JSW21
  • 2
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
The problem is that you are making an indirect reference to a Value-type (your structure) which results in it being classed as an expression.
You will have to declare a variable to hold a direct reference to the item and assign through that:


For index As Int16 = 0 To _cache_List.Count - 1
   Dim item As _cache = _cache_list(index)
   item.loading = false
Next

Open in new window

0
 
JSW21Author Commented:
Hi there
So I change the Structure into Class and it works.
I didnt know using structure will have different from class.

Do you think i am doing the right thing.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Structures are fundamentally different from classes in that they are value-types rather than reference types. Whether or not you need a struct rather than a class depends largely on its intended use.
0
 
JSW21Author Commented:
I will need to use class as I need to modify its values.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now