repl.it
@kironroy/

fullnames

C#

Correctly print out a full name with a list and foreach

fork
loading
Files
  • main.cs
  • main.exe
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
using System;
using System.Collections.Generic;

// https://stackoverflow.com/questions/18863187/how-can-i-loop-through-a-listt-and-grab-each-item

class MainClass 
{
  public static void Main (string[] args) {
      List<FullNamesModel> fullNamesList = new List<FullNamesModel>
        {
            new FullNamesModel{FirstName = "Richard", LastName = "Roma"},
            new FullNamesModel{FirstName = "Keith", LastName = "Ross"},
            new FullNamesModel{FirstName = "Grace", LastName = "Kelly"}
        };
        
        Console.WriteLine(); // breakline
        foreach (var fullNames in fullNamesList)
        {
           
            Console.WriteLine($"Hello {fullNames.FirstName} {fullNames.LastName}");
        }
    

        Console.ReadLine();
  }
}

public class FullNamesModel
{
    public string FirstName { get; set; }
    public string LastName { get; set; }

}