C#通过foreach语句搜索数组元素的代码
内容过程中,将内容过程中常用的内容做个备份,下面的内容段是关于C#通过foreach语句搜索数组元素的内容,希望能对小伙伴们有所用途。
using System; public class Search { public static void Main() { int[] nums = new int[10]; int val; bool found = false; for(int i = 0; i < 10; i++) nums[i] = i; val = 5; foreach(int x in nums) { if(x == val) { found = true; break; } } if(found) Console.WriteLine("Value found!"); } }
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。