repl.it
@kironroy/

instantiated_classes

C#

look at the notes

fork
loading
Files
  • main.cs
  • main.exe
  • PersonModel.cs
  • ProcessPerson.cs
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Globalization;

// in general instatiated classes store data.
// static classes are for stateless processing 
// reality, don't use many static class in applications

namespace ConsoleUI
{
    class Program
    {
      static void Main(string[] args)
      {
        // building a house from the blueprint (class)
        // PersonModel person = new PersonModel();

        // -- Following code is not ideal with instatiated classes
        
        // List<PersonModel> people = new List<PersonModel>();

        // people variable holds the address
        // there will be two addresses, (reference type)

        // Rita below

        // PersonModel person = new PersonModel();
        // person.firstName = "Rita;
        // people.Add(person);

        // Prefrable code 

        List<PersonModel> people = new List<PersonModel>();
        string firstName = "";
        string firstNameCaps;
        string lastNameCaps;

        do {
          Console.Write("What is your first name (or type exit to stop): ");
          firstName = Console.ReadLine();
          firstNameCaps = new CultureInfo("en-US").TextInfo.ToTitleCase(firstName);

          Console.Write("What is your last name: ");
          string lastName = Console.ReadLine();
          lastNameCaps = new CultureInfo("en-US").TextInfo.ToTitleCase(lastName);

          if (firstNameCaps.ToLower() != "exit")
          {
            PersonModel person = new PersonModel();
            person.FirstName = firstNameCaps;
            person.LastName = lastNameCaps;
            people.Add(person);
          }
        } while (firstNameCaps.ToLower() != "exit");

        Console.WriteLine();

        foreach (PersonModel p in people)
        {
            ProcessPerson.GreetPerson(p);
        }

        Console.ReadLine();


      }
   }
}