我正在爲我的兼職編程課程寫作業。我的代碼的問題是array.find()和搜索的結果。它應該(在我的理論中)在數組中搜索信息,然後將它們發佈給用戶,但是所有搜索結果都是一樣的:ass2task1.Program + customer這裏只有代碼的一部分,因爲老師告訴我們,我們可以在互聯網上,只要張貼問題,因爲我們當您轉換對象爲字符串("The forename resuts:" + resultforename
)不要張貼我們的整個代碼Array.find()提供了奇怪的結果
struct customer
{
public int customernumber;
public string customersurname;
public string customerforname;
public string customerstreet;
public string customertown;
public DateTime customerdob;
}
static void Main(string[] args)
{
customer[] customerdetails = new customer[99];
int selector = 0;
int selector2 = 0;
string vtemp = "";
string ctemp = "";
int searchnumber;
string searchforename; //variable/ array declaring
string searchsurname;
string searchtown;
DateTime searchdob;
customer resultnumber;
customer resultforename;
customer resultsurname;
customer resulttown;
customer resultdob;
if (selector2 == 2)
{
Console.Clear();
Console.WriteLine("Enter the forename you are looking for: ");
searchforename = (Console.ReadLine());
resultforename = Array.Find(customerdetails, customer => customer.customerforname == searchforename);
Console.Clear();
Console.WriteLine("Enter the surname you are looking for: "); // all of the searches comes out with ass2task1.Program+customer result
searchsurname = (Console.ReadLine());
resultsurname = Array.Find(customerdetails, customer => customer.customersurname == searchsurname);
Console.WriteLine("The forename resuts:" + resultforename);
Console.WriteLine("The surname resuts:" + resultsurname);
實際上你是否正在向任何客戶填充客戶詳細信息數組?代碼只顯示你聲明一個數組,它將容納99個項目 – 2014-08-29 14:50:17
在你的註釋行「ass2task1.Program + customer」什麼是ass2task1?另外,你將selecttor2設置爲0,然後有一個if塊,只有當selector2 var是2時纔會被命中,你能提供更相關的代碼來解決你的問題嗎?另外你是用數據填充你的數組嗎? – Kritner 2014-08-29 14:54:23
@Kritner'ass2task1'可能是命名空間。 – Ric 2014-08-29 14:55:47