fork download
  1. using System;
  2. using System.Diagnostics.Contracts;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. short numero = 2017;
  7. var m = new ShortYear(numero);
  8. Console.WriteLine(m);
  9. }
  10. }
  11. //provavelmente teria implemnetações de operadores, outros métodos e das interfaces
  12. //IFormattable, IConvertible, IComparable<ShortYear>, IEquatable<ShortYear> e outras
  13. public struct ShortYear {
  14. public byte Year;
  15. public const short Century = 1900;
  16. public ShortYear(short value) {
  17. Contract.Ensures(value >= Century && value < Century + 256);
  18. Year = (byte)(value - Century);
  19. }
  20. public ShortYear(int value) {
  21. Contract.Ensures(value >= Century && value < Century + 256);
  22. Year = (byte)(value - Century);
  23. }
  24. public static implicit operator short(ShortYear value) => (short)(value.Year + Century);
  25. public static implicit operator int(ShortYear value) => value.Year + Century;
  26. public override int GetHashCode() => Year.GetHashCode();
  27. public override String ToString() => (Year + Century).ToString();
  28. }
  29.  
  30. //https://pt.stackoverflow.com/q/221079/101
Success #stdin #stdout 0.02s 26252KB
stdin
Standard input is empty
stdout
2017