Delete Function for a Menu Driven Program

后端 未结 2 1375
终归单人心
终归单人心 2021-01-29 07:09

I\'m having trouble implementing the delete function, any help would be appreciated. I have a list called memberlist that stores the persons name and number. I have everything w

2条回答
  •  面向向阳花
    2021-01-29 07:56

    If you change Person[] to List as suggested by @Wiktor Zychla, this code should work well:

    public static List ML = new List();
    public static void DeleteMember(string name)
    {        
        var deleteMe = ML.Find(p => p.Name == name);
        if (deleteMe == null)
        {
            Console.WriteLine(name + " had not been added before.");
        }
        else
        {
            ML.Remove(deleteMe);
        }
    }
    

提交回复
热议问题