内容过程中, 将内容过程中常用的内容做个备份, 下面的内容段是关于 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!");
- }
- }
来源: http://www.bubuko.com/infodetail-2922475.html