J
JJ
Hi,
I am trying to understand the lifetime or scope of a
class in this project.
Here is the code that I am talking about:
private void PopulateCategoryCombo()
{
ListItem objListItem;
while (drSQL.Read())
{
objListItem = new ListItem(drSQL["CategoryName"].ToString
(),Convert.ToInt32(drSQL["CategoryID"]));
cbCategories.Items.Add(objListItem);
}
}
private void PopulateForm()
{
ListItem objListItem;
// Get Primary Key from Listbox
objListItem = (ListItem)
lstProducts.SelectedItem;
strSQL = "SELECT ProductID, " +
" ProductName, " +
" QuantityPerUnit, " +
" UnitPrice, " +
" UnitsInStock, " +
" UnitsOnOrder, " +
" ReorderLevel, " +
" Discontinued, " +
" SupplierID, " +
" CategoryID " +
"FROM Products " +
"WHERE ProductID = " + objListItem.ID;
}
Now these are fragments of code in these procedures. The
ListItem is a class in the sample project. In the first
proc. the class gets created and filled with Catagory Name
and CatID. Since it was first created in this procedure,
how come it didn't die as soon as the procedure was
finished? Because in the second procedure u can see it
gets recreated and Property ID of the class is called. The
ListItem class is defined as public class ListItem.
So from what I can tell is that the class persists through
the lifetime of the App, is this correct?
Thanks,
JJ
I am trying to understand the lifetime or scope of a
class in this project.
Here is the code that I am talking about:
private void PopulateCategoryCombo()
{
ListItem objListItem;
while (drSQL.Read())
{
objListItem = new ListItem(drSQL["CategoryName"].ToString
(),Convert.ToInt32(drSQL["CategoryID"]));
cbCategories.Items.Add(objListItem);
}
}
private void PopulateForm()
{
ListItem objListItem;
// Get Primary Key from Listbox
objListItem = (ListItem)
lstProducts.SelectedItem;
strSQL = "SELECT ProductID, " +
" ProductName, " +
" QuantityPerUnit, " +
" UnitPrice, " +
" UnitsInStock, " +
" UnitsOnOrder, " +
" ReorderLevel, " +
" Discontinued, " +
" SupplierID, " +
" CategoryID " +
"FROM Products " +
"WHERE ProductID = " + objListItem.ID;
}
Now these are fragments of code in these procedures. The
ListItem is a class in the sample project. In the first
proc. the class gets created and filled with Catagory Name
and CatID. Since it was first created in this procedure,
how come it didn't die as soon as the procedure was
finished? Because in the second procedure u can see it
gets recreated and Property ID of the class is called. The
ListItem class is defined as public class ListItem.
So from what I can tell is that the class persists through
the lifetime of the App, is this correct?
Thanks,
JJ