- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to count the number of items in a C# list?
Use the Array.Count property in C# to count the number of items in a list in C# −
Set the list
List<string> myList = new List<string>() { "electronics", "clothing", "appliances", "accessories" };
Now count the number of items in a list in C# −
myList.Count
The following is the complete code to count the number of items in a list −
Example
using System; using System.Collections.Generic; class Program { static void Main() { List myList = new List() { "electronics", "clothing", "appliances", "accessories" }; Console.WriteLine(myList.Count); } }
Advertisements