fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Windows.Forms;
  5.  
  6. namespace WindowsFormsApplication4
  7. {
  8. public partial class Form1 : Form
  9. {
  10. public Form1()
  11. {
  12. InitializeComponent();
  13. }
  14.  
  15. private void Form1_Load(object sender, EventArgs e)
  16. {
  17. var arr = new[]
  18. {
  19. new {Val1="1",Val2="B"},
  20. new {Val1="5",Val2="B"},
  21. new {Val1="3",Val2="B"},
  22. new {Val1="2",Val2="B"},
  23. new {Val1="4",Val2="B"}
  24. };
  25. var max = arr.Max(t => t.Val1, t => t);
  26. Debug.WriteLine(max.Val1 + " " + max.Val2);
  27. }
  28.  
  29. }
  30. public static class こんなMAX欲しかった
  31. {
  32. public static TResult Max<TSource, TValue, TResult>(this IEnumerable<TSource> source, Func<TSource, TValue> selecter, Func<TSource, TResult> resultSelecter) where TValue : IComparable, IComparable<TValue>
  33. {
  34. TValue maxVal = default(TValue);
  35. TResult result = default(TResult);
  36. foreach (var item in source)
  37. {
  38. var val = selecter(item);
  39. if (val.CompareTo(maxVal) >= 0)
  40. {
  41. maxVal = val;
  42. result = resultSelecter(item);
  43. }
  44. }
  45.  
  46. return result;
  47. }
  48. }
  49. }
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty