Chris

Chris

  • NA
  • 5
  • 20.8k

How to find the largest/longest string in a List

Jul 25 2010 11:31 PM

hello,
i am trying to learn c sharp and started playing with lists today and would like to know if i am headed in the right direction here or if i should look into making an Array or something else here is some sample code: now what i want to do is find the string with the largest/longest characters in it looking at the code it would be 'jessie' because there are 6 chars in that name. of course the program i am playing with has thousands of names. so i can just throw the log.Add(string) into a foreach loop that is simple enough but how i would i determine which string in that list is the longest, i dont really care about white space or non letters, just the char count. thanks in advance. O and i did search for this for about two hours before posting and it seems alot of people put there homework on here for help to get an A. i am not in school just trying to teach myself the language and would greatly appreciate any feed back. thanks
static
List<string> log = new List<string>();
string a = "John", b = "Sally", c = "jessie";
log.Add(a);
log.Add(b);
log.Add(c);
foreach(string L in log)
{
   Console.WriteLine(L);
}
//here i would like Console.WriteLine("{0} is the longest name.", /*longest char count in the list here*/);
 
 

 

Answers (4)