dba123
asked on
Obtain & check items in Generic list
I'm new to generics, and trying to check to see if the list I get back has any values. So far I've been unsuccessful in figuring out how to check this. Here's how I defined my generic list in the page I'm working with:
private List<sss.DataTier.Categori es.Categor y> categoryList = new List<sss.DataTier.Categori es.Categor y>();
...
private void LoadCategoryList()
{
categoryList = sss.DataTier.Categories.Ca tegoryCont entItem.Ge tCategoryL ist(sss.Da taTier.Cat egories.Co ntentItemT ype.Values .RecipeVer sion, recipeVersionID);
}
and finallly here's my If statement in which I'm trying to figure out how to check the list for categories:
protected bool CheckRequiredCategory()
{
if (categoryList. < 1) <<Not sure what to do here
{
return false;
}
else
{
return true;
}
Here's a print screen of values I get as options for the list: http://www.webfound.net/forum_posts/list_options.jpg
the type of records we're populating the list have column values such as the following:
C.CategoryID,
C.ParentCategoryID,
C.Name,
C.Description,
...
private List<sss.DataTier.Categori
...
private void LoadCategoryList()
{
categoryList = sss.DataTier.Categories.Ca
}
and finallly here's my If statement in which I'm trying to figure out how to check the list for categories:
protected bool CheckRequiredCategory()
{
if (categoryList. < 1) <<Not sure what to do here
{
return false;
}
else
{
return true;
}
Here's a print screen of values I get as options for the list: http://www.webfound.net/forum_posts/list_options.jpg
the type of records we're populating the list have column values such as the following:
C.CategoryID,
C.ParentCategoryID,
C.Name,
C.Description,
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
While I certainly love to get layups like these, I would be a schmo if i didn't point you to a great source of information. In VS 2005, double click on the word List in your source file, then press F1 key. A help file will launch with details about the "List" class.
ASKER
cool, thanks! I will also post that error tomorrow. I had actually this when I tried it before I posted this thread:
if(categoryList.Count == 0)
{
// categoryList has items in it
}
if(categoryList.Count == 0)
{
// categoryList has items in it
}
One reason that you would get a runtime error is if sss.DataTier.Categories.Ca tegoryCont entItem.Ge tCategoryL ist is returning null.
One reason you would get a compile time error is if sss.DataTier.Categories.Ca tegoryCont entItem.Ge tCategoryL ist does not return List<sss.DataTier.Categori es.Categor y>
One reason you would get a compile time error is if sss.DataTier.Categories.Ca
ASKER
ok, so if it returns null, how can I tell it not to error out and to change the null into zero?
ASKER
hmm, when I go to the properties of my .sln which is tied to all the projects I'm working with for this site, they're set to 'debug' in the configuration properties. So not sure what else here...
ASKER
also, comparing against 0 or < 1 doesnt' seem to work, it may be null.
doing this "seems" to work but I can't get my debug points to fire when using IIS mode
if (categoryList.Count == null)
doing this "seems" to work but I can't get my debug points to fire when using IIS mode
if (categoryList.Count == null)
ASKER
ok, I asked a team member. Here's what I had to do. I had set it to the worker process, however it was set to try to debug SQL. So I changed the following
1) Attach to worker process
2) Before clicking OK, changed the "Attach to" to Managed Code using the Select button. It was set to "Automatically determine the type of code to debug" prior which is why it was trying to debug my SQL instead of my managed code
1) Attach to worker process
2) Before clicking OK, changed the "Attach to" to Managed Code using the Select button. It was set to "Automatically determine the type of code to debug" prior which is why it was trying to debug my SQL instead of my managed code
private List<sss.DataTier.Categori es.Categor y> categoryList = new List<sss.DataTier.Categori es.Categor y>();
sss.DataTier.Categories.Ca tegory oSdc = new sss.DataTier.Categories.Ca tegory();
oSdc.CategoryID=000;
oSdc.ParentCategoryID=000;
oSdc.Name="XYZX";
oSdc.Description="XYZX";
categoryList.Add( oSdc);
protected bool CheckRequiredCategory()
{
if (oSDc.oSdc.ParentCategoryI D< 1)
{
return false;
}
else
{
return true;
}
Is this wat you are looking for
sss.DataTier.Categories.Ca
oSdc.CategoryID=000;
oSdc.ParentCategoryID=000;
oSdc.Name="XYZX";
oSdc.Description="XYZX";
categoryList.Add( oSdc);
protected bool CheckRequiredCategory()
{
if (oSDc.oSdc.ParentCategoryI
{
return false;
}
else
{
return true;
}
Is this wat you are looking for
ASKER