fork download
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. public class RingBuffer<T> : IEnumerable, IEnumerable<T> {
  7. public RingBuffer(int size) {
  8. elements = new T[size];
  9. end = 0;
  10. }
  11.  
  12. public void Add(T element) {
  13. elements[end] = element;
  14. ++end;
  15. if (end == elements.Length) {
  16. end = 0;
  17. }
  18. }
  19.  
  20. IEnumerator IEnumerable.GetEnumerator() {
  21. return this.GetEnumerator();
  22. }
  23.  
  24. public IEnumerator<T> GetEnumerator() {
  25. for (var i = (end == elements.Length - 1 ? 0 : end + 1); i != end;) {
  26. yield return elements[i];
  27. if (i == elements.Length - 1) {
  28. i = 0;
  29. } else {
  30. ++i;
  31. }
  32. }
  33. }
  34.  
  35. private T[] elements;
  36. private int end;
  37. }
  38.  
  39. public static class Program {
  40. public static void Main() {
  41. var buffer = new RingBuffer<int>(10);
  42.  
  43. for (var i = 0; i < 100; ++i) {
  44. buffer.Add(i);
  45. Console.WriteLine(string.Join(", ", buffer));
  46. }
  47. }
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(45,50): error CS1502: The best overloaded method match for `string.Join(string, string[])' has some invalid arguments
/usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)
prog.cs(45,50): error CS1503: Argument `#2' cannot convert `RingBuffer<int>' expression to type `string[]'
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty