Link to home
Start Free TrialLog in
Avatar of Mickeys
MickeysFlag for Sweden

asked on

How do I check if the class it is empty?

I cant get this right.  I need to know if there is something in my:
person.barnPnr[i]

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;
                    i++;
                }

Open in new window

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Did you check person[i].barnPnr != 0 ?
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];
    ...
}
Avatar of HarryNS
HarryNS

if ( person != null && person.barnPnr != null && person.barnPnr.Count > 0 )
            {
                // Your Logic... person.barnPnr[0]
            }
Avatar of Mickeys

ASKER

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

-------------------------------------------
philipjonathan:  
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


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

/M

ASKER CERTIFIED SOLUTION
Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mickeys

ASKER

That worked. Thx