CSharp9RecordAndWith.cs
using System; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Security.Cryptography.X509Certificates; | |
namespace ConsoleApp3 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("start"); | |
var bruno = new PersonRecord("Bruno", 40, true); | |
Console.WriteLine($"{bruno.ToString()}"); | |
Console.WriteLine($"Bruno Is Married created"); | |
var brunoMarried = bruno.CopyUsingMarriedTrue(); | |
Console.WriteLine($"{brunoMarried }"); | |
Console.WriteLine($"-----------------------------------"); | |
var valentino = new PersonRecord("Valentino", 13, false); | |
Console.WriteLine($"{valentino.ToString()}"); | |
Console.WriteLine($"Valentino Is Married created"); | |
var valentinoMarried = valentino.CopyUsingMarriedTrue(); | |
Console.WriteLine($"{valentinoMarried}"); | |
} | |
} | |
public record PersonRecord(string Name, int Age, bool Married = false) | |
{ | |
public Guid Id { get; init; } = Guid.NewGuid(); | |
public override string ToString() => $"Name: {Name} - Age: {Age} - Married: {Married} - Guid: {Id}"; | |
public PersonRecord CopyUsingMarriedTrue() => this with { Married = true }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment