嘿,我有一个结构数组,我需要以程序方式创建更改数组的值。我尝试使用像findindex这样的东西,但是它取代了所有的值(例如,将所有Mark改为Jack' s,即使我只想要一个特定的" Mark"来改变。) 我想要做的是让用户键入客户编号,然后更改此数组的所有值。因此,如果我搜索并想要编辑customernumber [0],我还可以更改所有其他值,如customersurname [0],customerfornemae [0]等。我只发布我觉得很重要的代码部分,但是如果你们需要的话我会更多。可以很容易地提供。
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;
int updatenumber;
string searchforename;
string searchsurname;
string searchtown;
DateTime searchdob;
customer resultnumber;
customer resultforename;
customer resultsurname;
customer resulttown;
customer resultdob;
customer updaterenumber;
if (selector == 3)
{
Console.Clear();
Console.WriteLine("Enter the customer number you wish to update: ");
updatenumber = int.Parse(Console.ReadLine());
updaterenumber = Array.Find(customerdetails, customer => customer.customernumber == updatenumber);
}