Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Obtain & check items in Generic list

Posted on 2006-11-28
11
210 Views
Last Modified: 2010-07-27
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.Categories.Category> categoryList = new List<sss.DataTier.Categories.Category>();

...

    private void LoadCategoryList()
    {
        categoryList = sss.DataTier.Categories.CategoryContentItem.GetCategoryList(sss.DataTier.Categories.ContentItemType.Values.RecipeVersion, 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,
                                 ...
      

0
Comment
Question by:dba123
  • 6
  • 3
11 Comments
 
LVL 7

Accepted Solution

by:
mjmarlow earned 500 total points
ID: 18034137
List has a property "Count" that you can access to get the number of items in it.

if(categoryList.Count > 0)
{
  // categoryList has items in it
}
0
 
LVL 1

Author Comment

by:dba123
ID: 18034143
yea, I did try that but it didn't like it, gave me an error.  I will post that error tomorrow...thanks.
0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 18034155
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.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Author Comment

by:dba123
ID: 18034265
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
}
0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 18036444
One reason that you would get a runtime error is if sss.DataTier.Categories.CategoryContentItem.GetCategoryList is returning null.  

One reason you would get a compile time error is if sss.DataTier.Categories.CategoryContentItem.GetCategoryList does not return List<sss.DataTier.Categories.Category>

0
 
LVL 1

Author Comment

by:dba123
ID: 18037278
ok, so if it returns null, how can I tell it not to error out and to change the null into zero?
0
 
LVL 1

Author Comment

by:dba123
ID: 18037606
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...
0
 
LVL 1

Author Comment

by:dba123
ID: 18037665
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)
0
 
LVL 1

Author Comment

by:dba123
ID: 18037782
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
0
 
LVL 1

Expert Comment

by:jagadeeshbandlamudi
ID: 18098340
private List<sss.DataTier.Categories.Category> categoryList = new List<sss.DataTier.Categories.Category>();
sss.DataTier.Categories.Category oSdc = new sss.DataTier.Categories.Category();
  oSdc.CategoryID=000;
   oSdc.ParentCategoryID=000;
   oSdc.Name="XYZX";
    oSdc.Description="XYZX";
  categoryList.Add( oSdc);
protected bool CheckRequiredCategory()
    {
        if (oSDc.oSdc.ParentCategoryID< 1)
        {
            return false;
        }
        else
        {
            return true;
        }


Is this wat you are looking for
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question