In this example we are finding out the maximum values from an int array without Max() Method.
You can find more similar examples of programming for this programming language in the site.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | static void Main(string[] args) { int[] numbers = { 5, 36, 23, 45, 15, 92, -5, 3, 33 }; int max = numbers[0]; foreach(int num in numbers) { Console.Write(num+" "); } Console.WriteLine(); Console.WriteLine("================================="); for(int i=0;i<numbers.Length;i++) { if(numbers[i]>max) { max = numbers[i]; } } Console.WriteLine("Max Value in Array :"+max); Console.ReadKey(); } |
Output: