Solved

Passing class derived from ArrayList

Posted on 2004-10-20
2
214 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Email Body 4 46
Async and await with MVC and Web Api 3 30
Get String split 5 33
Events in static methods 3 25
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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