代码如下: /* * 使用foreach来遍历数组并寻找负数 * User: www.51code.net * Date: 2009-6-30 * */ using System; namespace csb_ch8_7 { class Program { public static void Main(string[] args) { //定义并初始化一维整型数组 int[] score = { 89, 99, 85, -90, 78, -75, 80, 68, -92, 86 }; //使用foreach来遍历数组 foreach (int num in score) { //判断该元素是否为负数 if (num < 0) { //输出该元素 Console.WriteLine(num + "是负数"); } } // TODO: Implement Functionality Here Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } } }