fork download
  1. using System;
  2. using System.Text;
  3.  
  4. public class Foo {
  5. public Foo(int v) {
  6. Value = v;
  7. }
  8.  
  9. public int Value {get;}
  10. public static Bar operator*(string s, Foo f) {
  11. var sb = new StringBuilder();
  12. for (var i = 0; i < f.Value; i++) sb.Append(s);
  13. return new Bar(sb.ToString());
  14. }
  15. }
  16.  
  17. public class Bar {
  18. public Bar(string s) {
  19. Value = s;
  20. }
  21.  
  22. public string Value {get;}
  23. public static string operator*(Bar b, int c) {
  24. var sb = new StringBuilder();
  25. for (var i = 0; i < c; i++) sb.Append(b.Value);
  26. return sb.ToString();
  27. }
  28. public static implicit operator string(Bar b) => b.Value;
  29. public override string ToString() => Value;
  30. }
  31.  
  32. public class Test
  33. {
  34. public static void Main()
  35. {
  36. var u = new Foo(5);
  37. Console.WriteLine("!" * u);
  38. Console.WriteLine("!" * u * 4);
  39. }
  40. }
Success #stdin #stdout 0.04s 23912KB
stdin
Standard input is empty
stdout
!!!!!
!!!!!!!!!!!!!!!!!!!!