
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 find the size of a list in C#?
Declare and initialize a list.
var products = new List <string>(); products.Add("Accessories"); products.Add("Clothing"); products.Add("Footwear");
To get the size, use the Capacity property.
products.Capacity
Now let us see the complete code to find the size of a list.
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var products = new List <string>(); products.Add("Accessories"); products.Add("Clothing"); products.Add("Footwear"); Console.WriteLine("Our list...."); foreach(var p in products) { Console.WriteLine(p); } Console.WriteLine("Size of list = " + products.Capacity); } }
Output
Our list.... Accessories Clothing Footwear Size of list = 4
Advertisements