Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hello all,

i have a list of string.
i make it like this,

List<string> V = New List<string>();


i confuse to count that list(V).
may someone help me to solve my problem?
Posted
Updated 14-Apr-14 4:21am
v3
Comments
Sergey Alexandrovich Kryukov 14-Apr-14 11:07am    
Count what?
—SA

Everyone else has given you the answer to the question, the Count property will tell you how many elements are in the List<t>. What they DIDN'T tell you is that you would be far better served by reading the documentation on the List<t> class[^] and learning about it. If you didn't know about the Count property, there's a ton more information about that class you also don't know about and probably going to need.
 
Share this answer
 
List<string> V = new List<string>();

V.Add("Count 1");
V.Add("Count 2");
V.Add("Count 3");
V.Add("Count 4");

V.Count();
 
Share this answer
 
v2
V.Count gives the amount of the list size.

u can use a single like V[1].count, to count all strings inside the index 1


example:

XML
List<string> V = new List<string>();
V.Count();
 
Share this answer
 
v2
Comments
Meysam Toluie 15-Apr-14 2:20am    
I am sure you mean V[1].Length for single string size; because string is not List it's an array.
you can easily find it by googe


http://www.dotnetperls.com/list[^]
 
Share this answer
 
C#
//Use List count method to get no of list members

List<string> V = new List<string>();
int ListCount = V.Count;
 
Share this answer
 
v3
Hi...

Try this :

This is type of List:

C#
public class DemoClass
    {
        public string str1 { get; set; }
        public string str2 { get; set; }
        public string str3 { get; set; }
        public string str4 { get; set; }
        public string str5 { get; set; }
    }


and this is to define List & add type in the List :

C#
ist<democlass> Demo = new List<democlass>();
        DemoClass Data = new DemoClass();
        Data.str1 = "Hello";
        Data.str2 = "How";
        Data.str3 = "are";
        Data.str4 = "you";
        Data.str5 = "???";
        
        Demo.Add(Data);
</democlass></democlass>


HAve a good luck..... :) :) ;) ;)
 
Share this answer
 
Comments
Richard MacCutchan 14-Apr-14 12:28pm    
Why on earth would anyone want to use such convoluted code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900