0

Hi there, I have a problem with the search function I designed for my code.

using System;
using System.Collections.Generic;
using System.Text;



namespace ConsoleApplication
{
    public class Person
    {

        public string PerName, PerSal, PerPhone, PerPcode, perState, PerAddress, PerStrenum;


        public Person(string rec_name, string Srec_sal, string Srec_phone, string Srec_pcode, string rec_state, string rec_address, string Srec_strenum)
        {
            this.PerName = rec_name;
            this.PerSal = Srec_sal;
            this.PerPhone = Srec_phone;
            this.PerPcode = Srec_pcode;
            this.perState = rec_state;
            this.PerAddress = rec_address;
            this.PerStrenum = Srec_strenum;

        }

    }


    class Program
    {
        //Numeric validation
        static void NumberValidation(ref string DisplayNumText, ref int MinLengthVal, ref int MaxLengthVal, ref long MaxVal, ref int MinVal)
        {
            bool _numloop = true;
            string TempVal;
            int TempInt;

            while (_numloop)
            {
                Console.WriteLine(DisplayNumText);
                TempVal = Console.ReadLine();
                if (Int32.TryParse(TempVal, out TempInt) == false || TempInt >= MaxVal || TempInt <= MinVal
                || TempInt.ToString().Length > MaxLengthVal || TempInt.ToString().Length < MinLengthVal)
                {
                    Console.WriteLine("ERROR: invalid input");
                    _numloop = true;
                }
                else
                    _numloop = false;             
            }

        }//end of Numeric validation




   

        static void Main(string[] args)
        {
            int select = 0, count = 0;
            const int Limit = 50;
            string[][] people = new string[Limit][];
            while (select != 3)
            {
                Console.WriteLine("\n==== MAIN MENU ====");
                Console.WriteLine("1. Add new:");
                Console.WriteLine("2. View records: ");
                Console.WriteLine("3. Search records: ");
                Console.WriteLine("4. Delete records: ");
                Console.WriteLine("5. Exit: ");
                Console.WriteLine("==== **** **** ====\n");
                select = int.Parse(Console.ReadLine());

                switch (select)
                {
                    case 1:
                        if (count == Limit)
                        {
                            Console.WriteLine("Record's are full. Delete some.");
                            break;
                        }
                       
                        string DisplayNumText = "", TempVal = "", rec_state = "", rec_address = "", rec_name = "", Srec_sal, Srec_phone = "", Srec_pcode = "", Srec_strenum;
                        int MinLengthVal, MaxLengthVal, MinVal, rec_sal = 0,rec_phone = 0, rec_pcode = 0, rec_strenum = 0, tempInt;
                        long MaxVal;


                        DisplayNumText = "Enter Salary: ";
                        MinLengthVal = 4; MaxLengthVal = 6; MaxVal = 999999; MinVal = 0;
                        NumberValidation(ref DisplayNumText, ref MinLengthVal, ref MaxLengthVal, ref MaxVal, ref MinVal);
                        tempInt = rec_sal;

                        DisplayNumText = "Enter Phone number: ";
                        MinLengthVal = 8; MaxLengthVal = 10; MaxVal = 9999999999; MinVal = 0;
                        NumberValidation(ref DisplayNumText, ref MinLengthVal, ref MaxLengthVal, ref MaxVal, ref MinVal);
                        tempInt = rec_phone;
                    

                        DisplayNumText = "Enter post code: ";
                        MinLengthVal = 4; MaxLengthVal = 4; MaxVal = 9999; MinVal = 0;
                        NumberValidation(ref DisplayNumText, ref MinLengthVal, ref MaxLengthVal, ref MaxVal, ref MinVal);
                        tempInt = rec_pcode;


                        Console.WriteLine("Enter state: ");
                        rec_state = Console.ReadLine();

                        Console.WriteLine("enter adress: ");
                        rec_address = Console.ReadLine();

                        DisplayNumText = "Enter street number: ";
                        MinLengthVal = 1; MaxLengthVal = 5; MaxVal = 99999; MinVal = 1;
                        NumberValidation(ref DisplayNumText, ref MinLengthVal, ref MaxLengthVal, ref MaxVal, ref MinVal);
                        tempInt = rec_strenum;

                        Console.WriteLine("enter name: ");
                        rec_name = Console.ReadLine();


                        Srec_sal = rec_sal.ToString();
                        Srec_phone = rec_phone.ToString();
                        Srec_pcode = rec_pcode.ToString();
                        Srec_strenum = rec_strenum.ToString();
                        people[count++] = new string[] { rec_name, Srec_phone, Srec_pcode, rec_state, rec_address, Srec_strenum, Srec_sal };
                       
                        break;
                    case 2:
                        if (count == 0)
                            Console.WriteLine("Array is Empty - No Details to display");
                        else
                        {
                            for (int i = 0; i < count; i++)
                            {
                                Console.WriteLine("\n------ Record ------\n"
                                    + "Name: " + people[i][0] + "\n" +
                                    " Phone Number: " + people[i][1] + "\n" +
                                    "Post code: " + people[i][2] + "\n" +
                                    "State: " + people[i][4] + "\n" +
                                    "Address: " + people[i][5] + "\n" +
                                    "Salary: " + people[i][6] + "\n" +
                                 "\n------ ****** ------\n");
                            }
                        }

                        break;
                    case 3:
                        {
                            if (count == 0)
                                Console.WriteLine("Records Empty. No records to display.");
                            else
                            {
                                Console.Write("Enter Searching Name: ");
                                string searchName = Console.ReadLine();
                                int i;
                                for (i = 0; i < count; i++)
                                    if (people[i].rec_name == searchName)
                                    {
                                        Console.WriteLine(people[i]);
                                        break;
                                    }
                                if (i == count)
                                    Console.WriteLine("{0} is not on the list", searchName);
                            }
                        }
                        break;


                }
            }


        }


    }
}

Under rec_name I get an error telling me 'System.Array' does not contain a definition for 'rec_name' and no extension method 'rec_name' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)'
Im not sure why this would be, as rec_name is simply the name of the records needing to be searched.
Any help would be appreciated :)

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by finito
0

you need to change that line with

if (people[i][0] == searchName)

also within the if

you may want to do

Console.WriteLine("Name: " + people[i][0] + "\nPhone Number: " + people[i][1] + "\nPost code: " + people[i][2] + "\nState: " + people[i][4] + "\nAddress: " + people[i][5] + "\nSalary: " + people[i][6] + "\n") +
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.