Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApp1
- {
- class Integer
- {
- private Integer parent;
- public Integer()
- {
- parent = null;
- }
- public Integer (Integer incrementOperand)
- {
- parent = incrementOperand;
- }
- public bool IsZero => parent == null;
- public int ToInt()
- {
- if (IsZero) return 0;
- return 1 + parent.ToInt();
- }
- public static Integer FromInt(int x)
- {
- if (x < 0) throw new Exception("Eto neotritstelny tip!");
- if (x == 0) return new Integer(); //zero
- return new Integer(FromInt(x - 1));
- }
- public static Integer GetZero()
- {
- return new Integer();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Integer zero = Integer.GetZero();
- Integer one = new Integer(zero);
- Integer five = new Integer(new Integer(new Integer(new Integer(new Integer(Integer.GetZero())))));
- Console.WriteLine(zero.ToInt());
- Console.WriteLine(one.ToInt());
- Console.WriteLine(five.ToInt());
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement