Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Little beginner's query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stevetanner55@gmail.com - 13 Mar 2008 16:26 GMT
I have successfully created a small application that uses arraylists
of objects. However I have found it quite tiresome , when modifying
one of the objects in the arraylist to have to assign it to a
temporary instance before re-writing it.

something like...

temp_object1 = (object1) object1_arraylist[10]
temp_object1.element = "Something else"
object1_arraylist[10] = temp_object1

because it seems impossible to simply code:

(object1_arraylist[10]).element = "Something else"

Is there a simple way round this? Would pointers help?

Thanks for the tip!

steve tanner
Jon Skeet [C# MVP] - 13 Mar 2008 16:38 GMT
> I have successfully created a small application that uses arraylists
> of objects. However I have found it quite tiresome , when modifying
[quoted text clipped - 10 lines]
>
> (object1_arraylist[10]).element = "Something else"

Is object1 a struct by any chance? If so, it shouldn't really be
mutable to start with - mutable structs are a pain. If it's a class,
you should be able to do:

((object1)object1_arraylist[10]).element = "Something else"

> Is there a simple way round this? Would pointers help?

Using a List<T> would help a lot, unless you're still using .NET 1.1.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.