?
Solved

How do I check if the class it is empty?

Posted on 2009-04-19
6
Medium Priority
?
295 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:Mickeys
6 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24182374
Did you check person[i].barnPnr != 0 ?
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24182405
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];
    ...
}
0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24182409
if ( person != null && person.barnPnr != null && person.barnPnr.Count > 0 )
            {
                // Your Logic... person.barnPnr[0]
            }
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Mickeys
ID: 24182555
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

0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 2000 total points
ID: 24182631
That's strange, what about:
for (int i = 0; i < person.barnPnr.Count<string>(); i++)
0
 

Author Closing Comment

by:Mickeys
ID: 31572130
That worked. Thx
0

Featured Post

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.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

864 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