468,301 Members | 1,462 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Problem with - Edit Item of Collections.Generic.List(Of SearchAreaListItem)

I have a structure called SearchAreaListItem.

The structure has some properties.

The application implements this as a collection.generic.list(of SearchAreaListItem)

I load the collection up item at a time stuffing values into the item then adding the item to the
collection.
Now here come the rub.

There is one property attached to SearchAreaListItem, that I need to CHANGE so we can track whether the item has been accessed.

However when I try the following;
STEP 1: Dim SearchAreaList as new collection.generic.list(of SearchAreaListItem)

STEP 2: Call function to load each item and add to collection

STEP 3: Try to set the Accessed property on Item X

SearchAreaList.Item(x).Accessed = True

STEP 3 is not acceptable to Visual Studio and I get the design time error

Error 1 Expression is a value and therefore cannot be the target of an assignment.

Why can't I set a property of a structure through an index of a collection.generic.list(of SearchAreaListItem)??
Mar 27 '06 #1
3 5332
Why can't I set a property of a structure through an index of a collection.generic.list(of SearchAreaListItem)??


Becuase a structure givs you a value type, and therefore the List
indexer returns a copy of the instance. Even if the compiler let you
do what you want, you would modify the temporary copy, not the one in
the list. The solution is to use a class (a reference type) instead.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 27 '06 #2
snesbit,

In order to do what you want, SearchAreaListItem needs to be a class, not a
structure.

Kerry Moorman
"snesbit" wrote:
I have a structure called SearchAreaListItem.

The structure has some properties.

The application implements this as a collection.generic.list(of SearchAreaListItem)

I load the collection up item at a time stuffing values into the item then adding the item to the
collection.
Now here come the rub.

There is one property attached to SearchAreaListItem, that I need to CHANGE so we can track whether the item has been accessed.

However when I try the following;
STEP 1: Dim SearchAreaList as new collection.generic.list(of SearchAreaListItem)

STEP 2: Call function to load each item and add to collection

STEP 3: Try to set the Accessed property on Item X

SearchAreaList.Item(x).Accessed = True

STEP 3 is not acceptable to Visual Studio and I get the design time error

Error 1 Expression is a value and therefore cannot be the target of an assignment.

Why can't I set a property of a structure through an index of a collection.generic.list(of SearchAreaListItem)??

Mar 27 '06 #3
Snesbit,

It sounds for me so crazy

A generic list of a value that is placed on the stack

Cor
"snesbit" <sn*****@portaltech.com> schreef in bericht news:Oe**************@TK2MSFTNGP09.phx.gbl...
I have a structure called SearchAreaListItem.

The structure has some properties.

The application implements this as a collection.generic.list(of SearchAreaListItem)

I load the collection up item at a time stuffing values into the item then adding the item to the
collection.
Now here come the rub.

There is one property attached to SearchAreaListItem, that I need to CHANGE so we can track whether the item has been accessed.

However when I try the following;
STEP 1: Dim SearchAreaList as new collection.generic.list(of SearchAreaListItem)

STEP 2: Call function to load each item and add to collection

STEP 3: Try to set the Accessed property on Item X

SearchAreaList.Item(x).Accessed = True

STEP 3 is not acceptable to Visual Studio and I get the design time error

Error 1 Expression is a value and therefore cannot be the target of an assignment.

Why can't I set a property of a structure through an index of a collection.generic.list(of SearchAreaListItem)??
Mar 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jonathan | last post: by
6 posts views Thread by Dasn | last post: by
28 posts views Thread by walterbyrd | last post: by
4 posts views Thread by shapper | last post: by
11 posts views Thread by Louis.Soninhu | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.