[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2010-08-18
4
Medium Priority
?
862 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33469523
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
ID: 33471957
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 2000 total points
ID: 33472597
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
ID: 33479653
I will need to use class as I need to modify its values.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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