471,350 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Why not need ref when dataAdapter.Fill

ad
Hi,

When we use
myDataAdapter.Fill(myDataTable)

The parameter myDataTable is call by reference.

Why there is no need to add ref before the paremeter?
Feb 7 '06 #1
3 1311
"MyDataTable" is a reference type. Variables that are reference types consist
of only the pointer to that data. So, when you pass a parameter that is a
reference type into a method, it acts (through the pointer) directly on the
object.
Credit for the quintessential example of clarity in writing on this
difficult subject goes to MVP Jon Skeet in his description here:

http://www.yoda.arachsys.com/csharp/parameters.html

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"ad" wrote:
Hi,

When we use
myDataAdapter.Fill(myDataTable)

The parameter myDataTable is call by reference.

Why there is no need to add ref before the paremeter?

Feb 7 '06 #2
DataTable is the reference type rather than value type thus the
reference is passed and no need to use ref. It is a compile error if
you add ref here.

Feb 7 '06 #3
ad <fl****@wfes.tcc.edu.tw> wrote:
When we use
myDataAdapter.Fill(myDataTable)

The parameter myDataTable is call by reference.

Why there is no need to add ref before the paremeter?


The parameter not passed *by* reference - that means something slightly
different. Instead, the reference (which is the value of the
myDataAdapter variable) is passed by value.

See the page Peter referred you to for more details.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tee | last post: by
3 posts views Thread by Shapper | last post: by
3 posts views Thread by Stephen Noronha | last post: by
2 posts views Thread by susan.f.barrett | last post: by
6 posts views Thread by Tark Siala | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.