using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {            static int Find(int value, int[] array)
            {
            int i = 0;
            while (array[i] != value)
            {
                if (++i > array.Length)
                    Console.Write("Can not find");
            }
            return i;
            }
        
        
        }
            
          
         
        }
     }

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] array = new int[5] { 1,2,3,4,5};            int index =Find(5, array);
                if ( index < 0)
                {
                    Console.Write("Can not find");
                }
                else
                {
                    Console.Write(index);
                }
        
            }        private static int Find(int value, int[] array)
            {
                int i = 0;
                while (array[i] != value)
                {
                    if (++i > array.Length)
                        return -1;
                }
                return i;
            }
        }
    }