Solved

How to check if a list contains items? c#

Posted on 2009-05-08
6
2,067 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 500 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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