Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have list int
C#
List<int> buffer1 = new List<int>();

I added some values to this list string
C#
buffer1.Add(f);
buffer1.Add(f1);
buffer1.Add(f2);
buffer1.Add(f3);
buffer1.Add(f4);


How can I find the largest value of the list strin)

Thanks
John
Posted
Updated 6-Jan-14 1:59am
v3
Comments
lukeer 6-Jan-14 7:55am    
Are you sure it is new List();?
Could it be new List<YourListElementType>();?
If so, what type is YourListElementType?
Karthik_Mahalingam 6-Jan-14 8:11am    
Your question is wrong...

You can use List.Max() function to get the max value. I your case
C#
var maxValue = buffer1.Max();
 
Share this answer
 
Essentially you store the first value in a variable. Then loop through and compare. If it is larger then store that value. By the time you are done going through the whole list you'll have the largest value.

C#
Int32 largestVal = buffer1[0];
foreach (Int32 temp in buffer1)
{
   if (temp > largestVal)
     largestVal = temp;
}
 
Share this answer
 

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