none
quesion about instances RRS feed

  • Frage

  • Hi all

    I have a stupid beginners question ... :-))

    I have a class with a function as shown below.
    I am wondering what exactly is happening with
    the instance "local_DataTable" ?
    The instance is created locally within the function.
    When calling "return local_DataTable", is there a
    copy of this instance created or is a pointer of
    it given back ?

    The reason for this question is some trouble
    with this function on a Multithreadet environment.
    I have seen this function giving back wrong
    table and so on ...

    Would be nice to get back some feedback.

    Best regards
    Frank Uray


    public System.Data.DataTable GetDataTable(string Query)
    {
       System.Data.DataTable local_DataTable = new System.Data.DataTable();

       // fill the DataTable using a DataAdapter from SQL Server

       return local_DataTable;
    }

    Freitag, 24. September 2010 12:46

Antworten

  • When calling "return local_DataTable", is there a
    copy of this instance created or is a pointer of
    it given back ?
    (...)
    public System.Data.DataTable GetDataTable(string Query) //...


    System.Data.DataTable is a class. Therefore a reference (=pointer) is returned. The object itself is on the heap.

    (If it wouldn't be a class, but a [unboxed] struct, then a copy would be returned.)

    • Als Antwort markiert frank.uray Freitag, 24. September 2010 14:32
    Freitag, 24. September 2010 13:41