Click here to Skip to main content
15,894,825 members
Home / Discussions / C#
   

C#

 
AnswerRe: Is this good code practice? Pin
Pete O'Hanlon30-Apr-10 20:46
mvePete O'Hanlon30-Apr-10 20:46 
GeneralRe: Is this good code practice? Pin
venomation1-May-10 4:15
venomation1-May-10 4:15 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult1-May-10 5:41
mvePIEBALDconsult1-May-10 5:41 
GeneralRe: Is this good code practice? Pin
venomation1-May-10 7:18
venomation1-May-10 7:18 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult1-May-10 19:41
mvePIEBALDconsult1-May-10 19:41 
GeneralRe: Is this good code practice? [modified] Pin
venomation2-May-10 1:49
venomation2-May-10 1:49 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult2-May-10 4:07
mvePIEBALDconsult2-May-10 4:07 
GeneralRe: Is this good code practice? [modified] Pin
venomation2-May-10 5:58
venomation2-May-10 5:58 
This is the code that I have created so far, your comments are very helpful!


class Program
   {

       static void Main()
       {
           PersonManager personManager = new PersonManager();
           Menu mainMenu = new Menu(personManager);
           mainMenu.LoadActions();
           mainMenu.Display();

           Console.Read();

       }
   }


   class Person
{
    public Person(string forname, string surname, string title)
    {
        ForName = forname;
        SurName = surname;
        Title = title;
    }

    public string ForName { get; set; }

    public string SurName { get; set; }

    public string Title { get; set; }

    public override string ToString()
    {
        string fullName = string.Format("Name :{0} {1}\nTitle {2}", ForName, SurName, Title);
        return fullName;
    }

}


class PersonManager
{
    private readonly List<Person> _personList;

    public PersonManager()
    {
        //add a few people as a test
        _personList = new List<Person>(10)
                          {
                              new Person("James", "x", "Prog"),
                              new Person("Claire", "y", "Illu")
                          };

    }

    public void DumpAllToConsole()
    {
        //Prints the details of every person
        foreach (Person p in _personList)
        {
            Console.WriteLine(p.ToString());
        }
    }
}



class Menu
   {
       private readonly PersonManager _personManager;
       private delegate void DictionaryDel();
       private Dictionary<string, DictionaryDel> _action;

       public Menu(PersonManager personManager)
       {
           _personManager = personManager;

       }

       void GetInput(string input)
       {
           if (_action.Count == 0) return;
           if (!_action.ContainsKey(input)) return;

           _action[input]();
       }



       public void LoadActions()
       {
           _action = new Dictionary<string, DictionaryDel>
                         {
                             {"1", _personManager.DumpAllToConsole}
                         };
       }

       public void Display()
       {
           Console.WriteLine("Press 1 to display all students or 2 to quit");
           string input = Console.ReadLine();
           GetInput(input);
       }
   }



Is there anything else I should think about? Thanks ! Thumbs Up | :thumbsup: Big Grin | :-D

...For some reason turning "Encode "<" (and other HTML) characters when pasting" on or off does not allow me to show the dictionary generic structure Frown | :(

modified on Sunday, May 2, 2010 12:46 PM

GeneralRe: Is this good code practice? Pin
PIEBALDconsult2-May-10 10:24
mvePIEBALDconsult2-May-10 10:24 
GeneralRe: Is this good code practice? Pin
venomation2-May-10 11:41
venomation2-May-10 11:41 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult2-May-10 17:44
mvePIEBALDconsult2-May-10 17:44 
AnswerRe: Is this good code practice? Pin
venomation3-May-10 0:56
venomation3-May-10 0:56 
GeneralRe: Is this good code practice? Pin
PIEBALDconsult3-May-10 3:59
mvePIEBALDconsult3-May-10 3:59 
GeneralRe: Is this good code practice? Pin
Alaric_3-May-10 4:45
professionalAlaric_3-May-10 4:45 
GeneralRe: Is this good code practice? Pin
venomation3-May-10 5:04
venomation3-May-10 5:04 
QuestionCreate Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 9:44
mve#realJSOP30-Apr-10 9:44 
AnswerRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn30-Apr-10 10:04
sitebuilderLuc Pattyn30-Apr-10 10:04 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 11:35
mve#realJSOP30-Apr-10 11:35 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn30-Apr-10 11:41
sitebuilderLuc Pattyn30-Apr-10 11:41 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 12:04
mve#realJSOP30-Apr-10 12:04 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn30-Apr-10 12:30
sitebuilderLuc Pattyn30-Apr-10 12:30 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP30-Apr-10 23:10
mve#realJSOP30-Apr-10 23:10 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP1-May-10 3:07
mve#realJSOP1-May-10 3:07 
GeneralRe: Create Image in WinForms vs Asp.net Pin
Luc Pattyn1-May-10 3:32
sitebuilderLuc Pattyn1-May-10 3:32 
GeneralRe: Create Image in WinForms vs Asp.net Pin
#realJSOP1-May-10 7:35
mve#realJSOP1-May-10 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.