using System; using System.Diagnostics; using System.Collections.Generic; public class Tarjeta { public /*required*/ int Num { get => this._num; init { Debug.Assert( value > 0, "num. de tarjeta debe ser positivo" ); this._num = value; this.calculaCVC(); } } public /*required*/ DateOnly Caduca { get => this._caduca; init { Debug.Assert( value > DateOnly.FromDateTime( DateTime.Now ), "caducidad debe ser a futuro" ); this._caduca = value; } } public int CVC { get; private set; } public Tarjeta(int num, DateOnly caduca) { Debug.Assert( num > 0, "num. de tarjeta debe ser positivo" ); Debug.Assert( caduca > DateOnly.FromDateTime( DateTime.Now ), "caducidad debe ser a futuro" ); this.Num = num; this.Caduca = caduca; this.calculaCVC(); } private void calculaCVC() { this.CVC = this.Num % 1000; } public override string ToString() { return $"{this.Num} ({this.Caduca}, {this.CVC})"; } private int _num; private DateOnly _caduca; } public class Test { public static void Main() { /* var t1 = new Tarjeta { Num = 548901687, Caduca = new DateOnly( 2034, 11, 5 ) }; */ var t2 = new Tarjeta( 548901687, new DateOnly( 2034, 11, 5 ) ); // Console.WriteLine( t1 ); Console.WriteLine( t2 ); } }