Solved

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

Posted on 2010-08-18
4
684 Views
Last Modified: 2013-11-27
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
Comment
Question by:JSW21
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
 

Author Comment

by:JSW21
Comment Utility
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
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:JSW21
Comment Utility
I will need to use class as I need to modify its values.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now