Why not need ref when dataAdapter.Fill

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ad

    #1

    Why not need ref when dataAdapter.Fill

    Hi,

    When we use
    myDataAdapter.F ill(myDataTable )

    The parameter myDataTable is call by reference.

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


  • Peter Bromberg [C# MVP]

    #2
    RE: Why not need ref when dataAdapter.Fil l

    "MyDataTabl e" 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:



    Peter
    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "ad" wrote:
    [color=blue]
    > Hi,
    >
    > When we use
    > myDataAdapter.F ill(myDataTable )
    >
    > The parameter myDataTable is call by reference.
    >
    > Why there is no need to add ref before the paremeter?
    >
    >
    >[/color]

    Comment

    • Truong Hong Thi

      #3
      Re: Why not need ref when dataAdapter.Fil l

      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.

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Why not need ref when dataAdapter.Fil l

        ad <flying@wfes.tc c.edu.tw> wrote:[color=blue]
        > When we use
        > myDataAdapter.F ill(myDataTable )
        >
        > The parameter myDataTable is call by reference.
        >
        > Why there is no need to add ref before the paremeter?[/color]

        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 - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        Working...