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();
}
}
}
留言列表