Question about declaring a class

Hi,

I have found some code on the internet that i am trying to understand.

f.e: this line:
private ProductDatabase DataClass = new ProductDatabase();

How should I interpreted this line of code?

Peter

LVL 1
peterkiersAsked:
Who is Participating?
 
p_davisCommented:
if getcategories was a static method yes but it appears that it is public, in which case this syntax would be correct.
0
 
p_davisCommented:
it is a private class member instantiation.

by default this variable is only available to the class that it is declared in
0
 
Mrugesh1Commented:
private ProductDatabase DataClass = new ProductDatabase();

- private ProductDatabase indicates ProductDatabase is the private access class.
- ProductDatabase is the class name
- DataClass is the class object


0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
p_davisCommented:
private = declares that this member/variable is only for the use of the class in which it is declared.
ProductDatabase - declaring the type of this class member
DataClass - naming this instance of the class ProductDatabase
new ProductDatabase() - assigns the default value to the new instantiation through a constructor.
0
 
peterkiersAuthor Commented:
Oke thank you, but what I don't understand is f.e. this line in the code of the loadevent:

        private void MainForm_Load(object sender, EventArgs e)
        {
            TreeNode nodeParent;
            foreach (DataRow row in DataClass.GetCategories().Rows) <===================
            {
                nodeParent = lstvFoodDB.Nodes.Add(row[ProductDatabase.CategoryField.Name].ToString());
                 nodeParent.ImageIndex = 0;
                nodeParent.Tag = row;
                nodeParent.Nodes.Add("*");
            }
        }

Shouldn't this be: ...... ProductDatabase.GetCategories().Rows)

P.
0
 
peterkiersAuthor Commented:
Oke now I understand. Thanks p_davis.

P.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.