Solved

Passing class derived from ArrayList

Posted on 2004-10-20
2
215 Views
Last Modified: 2010-05-18
my class "List", is derived from "ArrayList".

I have a function, "foo" that accepts an "ArrayList" as a parameter.


foo(ref ArrayList al)
{
...
}


I want to pass an object of type "List" to foo:


foo(ref List )


but when i cast it, it says it needs to be an lvalue, because its a ref.


What should i be doing?

TIA.
0
Comment
Question by:dave_p_r_b
2 Comments
 
LVL 1

Accepted Solution

by:
gav_jackson earned 125 total points
ID: 12356253
you just pass the list object directly into foo (it will be a reference type anyway as it is an arraylist)

foo(List myList)
{
  //myList does not need to be cast as its already a "List" object
}


or am i totally missing the point?
0
 

Author Comment

by:dave_p_r_b
ID: 12356286
No, youve hit the point spot on.

Thanks for your help!

For anyone else, I found an article on msdn that explains  "Passing Reference types by value" .

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfPassingMethodParameters.asp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

21 Experts available now in Live!

Get 1:1 Help Now