using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Finder
{
     public class Finder
     {
         public static int Find<T>(T[] items, T item)
         {
             for (int i = 0; i < items.Length; i++)
             {
                 if(items[i].Equals(item))
                 {
                     return i;
                 }
             }
             return -1;
         }
     }
     class Program
     {
         static void Main(string[] args)
         {
             int pos = 0;
             int val = 5;
             int[] seqence = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            
             pos = Finder.Find<int>(seqence, val) + 1;
             Console.WriteLine("The position of number "+ val.ToString() + " is " + pos.ToString());
             //======================================================================
             string s = "Peter";
             string[] str = new string[] { "Jane", "Peter", "Ryan" };
       
             pos = Finder.Find<string>(str, s);
             Console.WriteLine("The position of string " + s + " is " + pos.ToString());
             Console.ReadLine();
         }
     }
}

sample code

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()