fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ArrayFunctions2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] A = new int[16];
  13.  
  14. A.Comment("Test1").LineFeed().Initialize(0, 1).RandomShuffle().ShowConsole();
  15.  
  16. return;
  17. }
  18. }
  19.  
  20. static class ArrayFunction
  21. {
  22. public static T[] Initialize<T>(this T[] Array, T Value)
  23. {
  24. for (int i = 0; i < Array.Count(); i++)
  25. {
  26. Array[i] = Value;
  27. }
  28.  
  29. return Array;
  30. }
  31.  
  32. public static T[] Initialize<T>(this T[] Array, T Value, dynamic Step)
  33. {
  34. for (int i = 0; i < Array.Count(); i++)
  35. {
  36. Array[i] = Value + (Step * i);
  37. }
  38.  
  39. return Array;
  40. }
  41. public static T[] ShowConsole<T>(this T[] Array, int LineFeed = 8, int Pad = 2, char Sepalator = ',')
  42. {
  43. string ShowString = string.Format(@"{0}0, {2}{1}{3}", '{', '}', Pad, Sepalator);
  44.  
  45. for (int i = 0; i < Array.Count(); i++)
  46. {
  47. Console.Write(ShowString, Array[i], Sepalator);
  48. if (i % LineFeed == (LineFeed - 1)) Console.WriteLine();
  49. }
  50.  
  51. return Array;
  52. }
  53.  
  54. public static T[] Filter<T>(this T[] Array, Func<T, bool> Action)
  55. {
  56. Queue<T> Q = new Queue<T>();
  57.  
  58. for (int i = 0; i < Array.Count(); i++)
  59. {
  60. if (Action(Array[i]) == true) Q.Enqueue(Array[i]);
  61. }
  62.  
  63. return Q.ToArray();
  64. }
  65. public static T[] Swap<T>(this T[] Array, int PosA, int PosB)
  66. {
  67. T Temp = Array[PosA];
  68. Array[PosA] = Array[PosB];
  69. Array[PosB] = Temp;
  70.  
  71. return Array;
  72. }
  73. public static T[] Sort<T>(this T[] Array, Func<T, T, bool> Action)
  74. {
  75. for (int i = 0; i < Array.Count(); i++)
  76. {
  77. for (int j = i + 1; j < Array.Count(); j++)
  78. {
  79.  
  80. if (Action(Array[i], Array[j]) == true) Array.Swap(i, j);
  81. }
  82. }
  83.  
  84. return Array;
  85. }
  86. public static T[] RandomShuffle<T>(this T[] Array)
  87. {
  88. Random Rnd = new Random();
  89. for (int i = 0; i < Array.Count(); i++)
  90. {
  91. Array.Swap(i, Rnd.Next(0, Array.Length - 1));
  92. }
  93.  
  94. return Array;
  95. }
  96. public static T[] LineFeed<T>(this T[] Array)
  97. {
  98. Console.WriteLine();
  99. return Array;
  100. }
  101. public static T[] Comment<T>(this T[] Array, string Comment)
  102. {
  103. Console.Write(Comment);
  104. return Array;
  105. }
  106. public static T[] MinMax<T>(this T[] Array, Func<T, T, bool> MaxAction)
  107. {
  108. T Max = Array[0];
  109. T Min = Array[0];
  110. for (int i = 0; i < Array.Count(); i++)
  111. {
  112. if (MaxAction(Max, Array[i]) == true) Max = Array[i];
  113. if (MaxAction(Min, Array[i]) == false) Min = Array[i];
  114. }
  115. return new T[2] { Min, Max };
  116. }
  117. public static int Counter<T>(this T[] Array, Func<T, T, bool> Action, T Value)
  118. {
  119. int Count = 0;
  120. for (int i = 0; i < Array.Count(); i++)
  121. {
  122. if (Action(Value, Array[i]) == true) Count++;
  123. }
  124. return Count;
  125. }
  126. }
  127. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(32,66): error CS1980: Dynamic keyword requires `System.Runtime.CompilerServices.DynamicAttribute' to be defined. Are you missing System.Core.dll assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty