C# Console Menu + Submenu's Help

Discussion in 'Programming & Software Development' started by Sarquiss, Jun 13, 2010.

  1. OP
    OP
    Sarquiss

    Sarquiss Member

    Joined:
    Jan 2, 2006
    Messages:
    568
    Location:
    Sydney
    I have just had a play around and came up with the following:-

    Code:
    public void deleteUser()
            {
                List<Data> result = search();
    
                foreach (Data i in result)
                {
                    Console.WriteLine("\n{0,0} {1,5}", i.userID, i.userName);
    	        }
                Console.WriteLine("\nPlease select member to delete by entering in userid");
                int x = int.Parse(Console.ReadLine());
    
                foreach (Data a in result)
                {
                    if (a.userID == x)
                    {
                        Users.Remove(a);
                    }
                }
            }
    
            public List<Data> search()
            {
                Console.Write("Please Enter Your Username of Member: ");
                string userToFind = Console.ReadLine();
                List<Data> results = Users.FindAll(
                delegate(Data bk)
                {
                    return bk.userName.Contains(userToFind);
                });
    
                return results;
            }
    
    I will have a look into Linq and have another play around. But are there any other recommendations to clean up the code??? :)

    EDIT -

    Here is how I am structuring my List

    Code:
    class Data
        {
            public int    userID         { get; set; }
            public string userName       { get; set; }
            public string userAddress    { get; set; }
            public string userEmail      { get; set; }
            public string userPhone      { get; set; }
        }
    
    Code:
    public void fillList()
            {
                addUser("Bruce Caldwell",  "123 Washington Drive", "0412345678", "caldwell@gmail.com");
                addUser("Justin Halpern",  "13 Ashmore Road",      "0755894712", "jhalpern@gmail.com");
                addUser("Stephenie Meyer", "3 Benowa Street",      "0398784541", "step@yahoo.com");
                addUser("Bruce Yoddaly", "1 Bayswater Ave",        "0755874961", "Yoddaly@gmail.com");
                addUser("Maxine Paetro",   "55 Broadbeach Ave",    "0458965214", "max@gmail.com");
                addUser("Bruce Centre", "2985 Pacific Drive",      "0145198745", "Centre@gmail.com");
                addUser("Suzanne Collinsi","362 Australia Drive",  "0287547562", "suzanne12@bond.com");
            }
    
    EDIT #2 - Just in case anyone is wondering the above data is all fake LOL
     
    Last edited: Jun 28, 2010

Share This Page

Advertisement: