題目
做一個 方法
代碼
namespace _2018_12_13_練習(xí)1
{
class Program
{
static void Main(string[] args)
{/*
*在保存了多個學(xué)生姓名的數(shù)組中,指定查找區(qū)間,查找某個學(xué)生姓名并顯示是否查找成功
* */
//1 定義一個數(shù)組
string[] list = { "張三", "豬八戒", "妲己", "海王" };
bool resule = Search(list ,1,2,"海王");
Console.Write(resule);
Console.ReadKey();
}
/*
* 在指定去檢查找某個學(xué)生姓名,如果找到,返回true,如果沒有找到,返回 false
* list:保存學(xué)生姓名的數(shù)組
* start:查找區(qū)間開始的位置
* len:查找區(qū)間的長度
* username:需要查找的姓名
* */
static bool Search(string[] list, int start, int len, string username)
{
bool ret = false;
if ((start + len) > list.Length)
{
ret = false;
}
else
{
for (int i = start; i < start + len; i++)
{
if (username == list[i])
{
ret = true;
break;
}
}
}
return ret;
}
}
}
效果圖
