Thanks for your response Nicholas .
but I'm still a bit confused...
When da.Fill returns, my DataTable param var is populated. That implies
that it was passed by ref, correct ? But, I thought (and read, I think)
in C#, in order to declare a parameter as ref, you need to declare it as
such. You are right in your example, when I create a sub of my own,
similiar to the da.Fill method, the param is not affected on the calling
side. So why is the DataAdapter Fil method able to affect the DT param,
and not mine ?
Thanks for being patient. I'm a veteran VB programmer, so this is a
humbling experience.
Bill : )
Nicholas Paldino said:
Bill,
This is incorrect. dt is not passed by ref. Rather, DataTable is a
reference type, meaning that when you assign it, you pass the reference.
If you were passing the parameter by ref, then you would be able to
change the reference that you are passing in.
For example, if the Fill method did something like this:
public void Fill(DataTable table)
{
table = new DataTable();
}
When you return, you will see that the parameter passed to table
doesn't in fact change.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Bill H said:
i'm new to C#...
How can I create an out or ref param for a method without having to
declare it in the caling code ? Like the DataAdapter can do on its Fill
method.
DataTable dt = new DataTable();
SqlDataAdapter.Fill(dt);
'dt' is passed by ref, but it is not required to pass it as such:
SqlDataAdapter.Fill(ref dt);
Thanks,
Bill