0

Hey I have an array of structs and i need to create in program way to change the values of the arrays. I tried using things like findindex but it replaced all values (e.g changed all of Mark's into Jack's even though i only want the one specific "Mark" to change.) What i want to do is make user type the customer number and then change all the values of this array. So if i search and want to edit customernumber[0] i can also change all other values like customersurname[0], customerfornemae[0] and so on. I am posting only the parts of code i think are important but if you guys need any more I' can easily provide.

 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);

                }
Skretek112
  • 11
  • 3
  • Structs are designed to [be immutable](http://stackoverflow.com/questions/608542/immutability-of-structs), use a class instead if you want to change the values. – Tim Schmelter Oct 06 '14 at 12:41
  • `struct`s don't have "columns"; however, that is a very poor choice for a `struct`, IMO - should be a `class`. – Marc Gravell Oct 06 '14 at 12:43
  • " I tried using things like findindex but it replaced all values (e.g changed all of Mark's into Jack's even though i only want the one specific "Mark" to change.) " - no, it didn't; that isn't how it works; you might want to clarify what you did there... – Marc Gravell Oct 06 '14 at 12:49
  • I used structs becouse that's what I have learned, Never touched classes. Would it be hard to change this struct into a class? How would I search and edit if it were a class? – Skretek112 Oct 06 '14 at 13:01
  • Are there always going to be 99 customers in your array or is this just an arbitrary number that you think is large enough to cover however many customers that you might add to the array. If it is the latter user `List` which is resizeable. – Ben Robinson Oct 06 '14 at 13:03

0 Answers0