// $Id: methcall.csharp,v 1.0 2002/02/14 13:01:00 dada Exp $ // http://dada.perl.it/shootout/ using System; class Toggle { public bool state = true; public Toggle(bool start_state) { this.state = start_state; } public bool value() { return(this.state); } public Toggle activate() { this.state = !this.state; return(this); } } class NthToggle : Toggle { int count_max = 0; int counter = 0; public NthToggle(bool start_state, int max_counter) : base(start_state) { this.count_max = max_counter; this.counter = 0; } public new NthToggle activate() { this.counter += 1; if (this.counter >= this.count_max) { this.state = !this.state; this.counter = 0; } return(this); } } class App { public static int Main(String[] args) { bool val = true; int n; Toggle toggle = new Toggle(val); NthToggle ntoggle = new NthToggle(true, 3); n = System.Convert.ToInt32(args[0]); if(n < 1) n = 1; for (int i=0; i<n; i++) { val = toggle.activate().value(); } Console.WriteLine((val ? "true" : "false")); for (int i=0; i<n; i++) { val = ntoggle.activate().value(); } Console.WriteLine((val ? "true" : "false")); return(0); } }