How do I check if the class it is empty?

Posted on 2009-04-19
Last Modified: 2012-05-06
I cant get this right.  I need to know if there is something in my:

but if I write person.barnPnr[i] and then .  I can get a Count but that looks like Count< > so how do I check if there  is something in it or not?
int i = 0;

                //while (person.barnPnr[i]. > 0)

                while(person.barnPnr.Count<int> != 0)


                    message = message + person.barnForNamn;

                    message = message + "\n";

                    message = message + person.barnEfterNamn;

                    message = message + "\n";

                    message = message + person.barnPnr;



Open in new window

Question by:Mickeys
    LVL 53

    Expert Comment

    Did you check person[i].barnPnr != 0 ?
    LVL 18

    Expert Comment

    Is barnPnr a List<>? Do you wish to iterate through it?
    for (int i = 0; i < person.barnPnr.Count; i++)
        YourObjectTypeHere barnPnr = person.barnPnr[i];
    LVL 6

    Expert Comment

    if ( person != null && person.barnPnr != null && person.barnPnr.Count > 0 )
                    // Your Logic... person.barnPnr[0]

    Author Comment

    while (person.barnPnr[i] != 0)
        //error. Cant check string to int

    barnPnr is a public List<String> barnPnr;

    for (int i = 0; i < person.barnPnr.Count; i++)

    //error    Error      1      Operator '<' cannot be applied to operands of type 'int' and 'method group'      C:\Documents and Settings\MFL\Dokumenter\Visual Studio 2008\Projects\WebApplication1\WebApplication1\Class1.cs      37      33      WebApplication1

    while(person.barnPnr != null)
    works but I need to iterat throw the list util it is empty


    LVL 18

    Accepted Solution

    That's strange, what about:
    for (int i = 0; i < person.barnPnr.Count<string>(); i++)

    Author Closing Comment

    That worked. Thx

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now