After learning the program, I felt that writing code was very interesting. So I wrote down my feelings. The first time I wrote a blog, it may have been a time for cainiao. I believe it will be a good job!
For and foreach array traversal comparison
Very simple program. Don't explain it!
Using System; using System. collections. generic; using System. linq; using System. text; namespace ConsoleApplication1 {class Program {static void Main (string [] args) {int [] nums = {3, 5, 99, 23, 53, 88 }; // define the array int max = 0; for (int I = 0; I <nums. length; I ++) // for traversing the Array {if (nums [I]> max) {max = nums [I] ;}} Console. writeLine ("for traversing array demo:" + max); Console. writeLine ("========================================== ================== "); foreach (var p in nums) // use foreach to traverse {if (p> max) {max = p ;}} Console. writeLine ("foreach traversal array demo:" + max );}}}
Result: