WTF

CSharp · Console

/Program.cs

#nullable enable

using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
	public static void Main()
	{
		var userNames = new List<string>{"Pelle Coltau", "Søren Lund"};
		var persons = userNames.Select(x => new Person{Name = x});
		
		foreach (var person in persons)
		{
			person.FamilyName = person.Name.Split(' ').Last();
		}

		var familyNameList = persons.Select(x => x.FamilyName).ToList();
		Console.WriteLine(string.Join(", ", familyNameList));
	}

	private class Person
	{
		public required string Name { get; init; }

		public string? FamilyName { get; set; }
	}
}

#nullable disable
;