Question about some snippets in an article

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

    Question about some snippets in an article

    Code Snippet 1


    public class CustomerInfoCol lection : IList
    {
    private ArrayList m_alCustomerInf o;
    private DataSet m_ds;

    public CustomerInfoCol lection()
    {
    m_alCustomerInf o = new ArrayList();
    }

    public void GetAllCustomers ()
    {
    // Instantiate a Data Layer class to fill the DataSet
    // The specific method will fill a DataTable named "Customers"
    // See Part 3 for further details.
    DCustomers cust = new DCustomers();
    m_ds = cust.SelectAllC ustomers();

    // Iterate on all rows and create an Info object per row
    foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
    m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
    }

    }


    Code Snippet 2

    public class CustomerInfo
    {
    private DataRow m_dr;
    private CustomerInfoCol lection m_cic;

    public CustomerInfo(Cu stomerInfoColle ction coll, DataRow dr)
    {
    m_cic = coll;
    m_dr = dr;
    }

    }


    These snippets are from an article I'm currently reviewing. I just had a
    question about what a certain line of code is doing. The line in question is
    as follows:

    // Iterate on all rows and create an Info object per row
    foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
    m_alCustomerInf o.Add(new CustomerInfo(th is, dr));

    When instantiating a new CustomerInfo object, it's passing 2 parms:

    CustomerInfo(th is, dr)

    Does this mean that for each customerinfo object that's added, the object
    contains a collection object as well?

    thanks,
    rodchar


  • Peter Rilling

    #2
    Re: Question about some snippets in an article

    It contains a "reference" to a collection object (with emphasis on
    reference).

    "rodchar" <rodchar@discus sions.microsoft .com> wrote in message
    news:A35DB3DE-0574-45AE-B938-C0436F82C548@mi crosoft.com...[color=blue]
    > Code Snippet 1
    >
    >
    > public class CustomerInfoCol lection : IList
    > {
    > private ArrayList m_alCustomerInf o;
    > private DataSet m_ds;
    >
    > public CustomerInfoCol lection()
    > {
    > m_alCustomerInf o = new ArrayList();
    > }
    >
    > public void GetAllCustomers ()
    > {
    > // Instantiate a Data Layer class to fill the DataSet
    > // The specific method will fill a DataTable named "Customers"
    > // See Part 3 for further details.
    > DCustomers cust = new DCustomers();
    > m_ds = cust.SelectAllC ustomers();
    >
    > // Iterate on all rows and create an Info object per row
    > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
    > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
    > }
    >
    > }
    >
    >
    > Code Snippet 2
    >
    > public class CustomerInfo
    > {
    > private DataRow m_dr;
    > private CustomerInfoCol lection m_cic;
    >
    > public CustomerInfo(Cu stomerInfoColle ction coll, DataRow dr)
    > {
    > m_cic = coll;
    > m_dr = dr;
    > }
    >
    > }
    >
    >
    > These snippets are from an article I'm currently reviewing. I just had a
    > question about what a certain line of code is doing. The line in question[/color]
    is[color=blue]
    > as follows:
    >
    > // Iterate on all rows and create an Info object per row
    > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
    > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
    >
    > When instantiating a new CustomerInfo object, it's passing 2 parms:
    >
    > CustomerInfo(th is, dr)
    >
    > Does this mean that for each customerinfo object that's added, the object
    > contains a collection object as well?
    >
    > thanks,
    > rodchar
    >
    >[/color]


    Comment

    • rodchar

      #3
      RE: Question about some snippets in an article

      why pass a ref of the collection? i understand of the datarow but not the
      collection?

      "rodchar" wrote:
      [color=blue]
      > Code Snippet 1
      >
      >
      > public class CustomerInfoCol lection : IList
      > {
      > private ArrayList m_alCustomerInf o;
      > private DataSet m_ds;
      >
      > public CustomerInfoCol lection()
      > {
      > m_alCustomerInf o = new ArrayList();
      > }
      >
      > public void GetAllCustomers ()
      > {
      > // Instantiate a Data Layer class to fill the DataSet
      > // The specific method will fill a DataTable named "Customers"
      > // See Part 3 for further details.
      > DCustomers cust = new DCustomers();
      > m_ds = cust.SelectAllC ustomers();
      >
      > // Iterate on all rows and create an Info object per row
      > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
      > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
      > }
      >
      > }
      >
      >
      > Code Snippet 2
      >
      > public class CustomerInfo
      > {
      > private DataRow m_dr;
      > private CustomerInfoCol lection m_cic;
      >
      > public CustomerInfo(Cu stomerInfoColle ction coll, DataRow dr)
      > {
      > m_cic = coll;
      > m_dr = dr;
      > }
      >
      > }
      >
      >
      > These snippets are from an article I'm currently reviewing. I just had a
      > question about what a certain line of code is doing. The line in question is
      > as follows:
      >
      > // Iterate on all rows and create an Info object per row
      > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
      > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
      >
      > When instantiating a new CustomerInfo object, it's passing 2 parms:
      >
      > CustomerInfo(th is, dr)
      >
      > Does this mean that for each customerinfo object that's added, the object
      > contains a collection object as well?
      >
      > thanks,
      > rodchar
      >
      >[/color]

      Comment

      • Peter Rilling

        #4
        Re: Question about some snippets in an article

        Good question. From this amount of code, that is something that I cannot
        answer. Normally a hierarchical structure will hold a reference to the
        parent object, but I do not know why the collection needs to be held.

        "rodchar" <rodchar@discus sions.microsoft .com> wrote in message
        news:33ECE90D-6A66-485C-A760-0AE404DB95B3@mi crosoft.com...[color=blue]
        > why pass a ref of the collection? i understand of the datarow but not the
        > collection?
        >
        > "rodchar" wrote:
        >[color=green]
        > > Code Snippet 1
        > >
        > >
        > > public class CustomerInfoCol lection : IList
        > > {
        > > private ArrayList m_alCustomerInf o;
        > > private DataSet m_ds;
        > >
        > > public CustomerInfoCol lection()
        > > {
        > > m_alCustomerInf o = new ArrayList();
        > > }
        > >
        > > public void GetAllCustomers ()
        > > {
        > > // Instantiate a Data Layer class to fill the DataSet
        > > // The specific method will fill a DataTable named "Customers"
        > > // See Part 3 for further details.
        > > DCustomers cust = new DCustomers();
        > > m_ds = cust.SelectAllC ustomers();
        > >
        > > // Iterate on all rows and create an Info object per row
        > > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
        > > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
        > > }
        > >
        > > }
        > >
        > >
        > > Code Snippet 2
        > >
        > > public class CustomerInfo
        > > {
        > > private DataRow m_dr;
        > > private CustomerInfoCol lection m_cic;
        > >
        > > public CustomerInfo(Cu stomerInfoColle ction coll, DataRow dr)
        > > {
        > > m_cic = coll;
        > > m_dr = dr;
        > > }
        > >
        > > }
        > >
        > >
        > > These snippets are from an article I'm currently reviewing. I just had a
        > > question about what a certain line of code is doing. The line in[/color][/color]
        question is[color=blue][color=green]
        > > as follows:
        > >
        > > // Iterate on all rows and create an Info object per row
        > > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
        > > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
        > >
        > > When instantiating a new CustomerInfo object, it's passing 2 parms:
        > >
        > > CustomerInfo(th is, dr)
        > >
        > > Does this mean that for each customerinfo object that's added, the[/color][/color]
        object[color=blue][color=green]
        > > contains a collection object as well?
        > >
        > > thanks,
        > > rodchar
        > >
        > >[/color][/color]


        Comment

        • rodchar

          #5
          Re: Question about some snippets in an article

          thanks for the help. in case you're curious:

          Code Snippet 3 & 4 in the article.
          rodchar

          "Peter Rilling" wrote:
          [color=blue]
          > Good question. From this amount of code, that is something that I cannot
          > answer. Normally a hierarchical structure will hold a reference to the
          > parent object, but I do not know why the collection needs to be held.
          >
          > "rodchar" <rodchar@discus sions.microsoft .com> wrote in message
          > news:33ECE90D-6A66-485C-A760-0AE404DB95B3@mi crosoft.com...[color=green]
          > > why pass a ref of the collection? i understand of the datarow but not the
          > > collection?
          > >
          > > "rodchar" wrote:
          > >[color=darkred]
          > > > Code Snippet 1
          > > >
          > > >
          > > > public class CustomerInfoCol lection : IList
          > > > {
          > > > private ArrayList m_alCustomerInf o;
          > > > private DataSet m_ds;
          > > >
          > > > public CustomerInfoCol lection()
          > > > {
          > > > m_alCustomerInf o = new ArrayList();
          > > > }
          > > >
          > > > public void GetAllCustomers ()
          > > > {
          > > > // Instantiate a Data Layer class to fill the DataSet
          > > > // The specific method will fill a DataTable named "Customers"
          > > > // See Part 3 for further details.
          > > > DCustomers cust = new DCustomers();
          > > > m_ds = cust.SelectAllC ustomers();
          > > >
          > > > // Iterate on all rows and create an Info object per row
          > > > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
          > > > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
          > > > }
          > > >
          > > > }
          > > >
          > > >
          > > > Code Snippet 2
          > > >
          > > > public class CustomerInfo
          > > > {
          > > > private DataRow m_dr;
          > > > private CustomerInfoCol lection m_cic;
          > > >
          > > > public CustomerInfo(Cu stomerInfoColle ction coll, DataRow dr)
          > > > {
          > > > m_cic = coll;
          > > > m_dr = dr;
          > > > }
          > > >
          > > > }
          > > >
          > > >
          > > > These snippets are from an article I'm currently reviewing. I just had a
          > > > question about what a certain line of code is doing. The line in[/color][/color]
          > question is[color=green][color=darkred]
          > > > as follows:
          > > >
          > > > // Iterate on all rows and create an Info object per row
          > > > foreach (DataRow dr in m_ds.Tables["Customers"].Rows)
          > > > m_alCustomerInf o.Add(new CustomerInfo(th is, dr));
          > > >
          > > > When instantiating a new CustomerInfo object, it's passing 2 parms:
          > > >
          > > > CustomerInfo(th is, dr)
          > > >
          > > > Does this mean that for each customerinfo object that's added, the[/color][/color]
          > object[color=green][color=darkred]
          > > > contains a collection object as well?
          > > >
          > > > thanks,
          > > > rodchar
          > > >
          > > >[/color][/color]
          >
          >
          >[/color]

          Comment

          Working...