Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to check if a list contains items? c#

Posted on 2009-05-08
6
Medium Priority
?
2,089 Views
Last Modified: 2012-05-06
HI all,

I have a list wich I need to check if it contains any items or not. If it does not I need to show a warning that it has to have at least one item.

How to check this?
Probably pretty simple but can't seem to find it right now...

Grts
0
Comment
Question by:Pit76
[X]
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
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24335948

List<string> someList = new List<string>();
 
someList.Count > 0

Open in new window

0
 
LVL 12

Accepted Solution

by:
wht1986 earned 2000 total points
ID: 24335991
You did say what kind of list you are referring to so here are a couple of examples

List<string> list1 = new List<string>();
if (list1.Count == 0) { /* Display Error */ }

string[] list2 = new string[] { "", "", "" };
if (list2.Length == 0) { /* Display Error */ }

ListBox lb = new ListBox();
if (lb.Items.Count == 0) { /* Display Error */ }
0
 

Author Comment

by:Pit76
ID: 24336039
Hi,

Indeed I forgot to tell that. It's the first one.
Thought it was going to be simple, about the same as checking if a DataSet has rows...

Anyway thx for putting my nose on it :)

Grts
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:Pit76
ID: 31579432
Thx :)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24336062
Wow...  I don't even know what to say.
0
 

Author Comment

by:Pit76
ID: 24339711
Yeah I know sry.
 I should have split the points but tbh I looked over your answer, as stupid as it may sound...

You've helped me before so I feel a little bad about it...

Greetings.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

610 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