fork(1) download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Collections.Generic;
  6.  
  7. namespace ConsoleApp1
  8. {
  9. public delegate void MyDelegate(string telemId, string className, string propName, object value);
  10. public delegate void ReportCallback();
  11.  
  12. struct MyStruct {
  13. string telemId;
  14. MyDelegate reporter;
  15. double a;
  16. public double b;
  17. double c;
  18. public MyStruct(string telemIdVal, MyDelegate reportProc, double valA, double valB, double valC){
  19. telemId = telemIdVal;
  20. reporter = reportProc;
  21. a = valA;
  22. b = valB;
  23. c = valC;
  24. }
  25. public void Report() {
  26. reporter(this.telemId, this.GetType().ToString(), "a", a);
  27. reporter(this.telemId, this.GetType().ToString(), "b", b);
  28. reporter(this.telemId, this.GetType().ToString(), "c", c);
  29. }
  30.  
  31. }
  32.  
  33. public class Program
  34. {
  35. public static void ReportTelemetry(string telemId, string className, string propName, object value) {
  36. Console.WriteLine(String.Format("{0} - {1}.{2}: {3}", telemId, className, propName, value));
  37. }
  38.  
  39. public static void Main() {
  40. var altitude = new MyStruct("Altitude Controller", new MyDelegate(ReportTelemetry), 15, 2, Math.PI);
  41. var speed = new MyStruct("Speed Controller", new MyDelegate(ReportTelemetry), 22, 15, Math.PI);
  42.  
  43. var d = new Dictionary<object, ReportCallback>();
  44. d.Add(altitude, new ReportCallback(altitude.Report));
  45. d.Add(speed, speed.Report);
  46.  
  47. foreach (var kvp in d){
  48. kvp.Value();
  49. }
  50.  
  51. altitude.b = 123123.12;
  52.  
  53. foreach (var kvp in d){
  54. kvp.Value();
  55. }
  56.  
  57. Console.WriteLine(altitude.b.ToString());
  58. }
  59.  
  60. }
  61. }
Success #stdin #stdout 0.01s 15216KB
stdin
Standard input is empty
stdout
Altitude Controller - ConsoleApp1.MyStruct.a: 15
Altitude Controller - ConsoleApp1.MyStruct.b: 2
Altitude Controller - ConsoleApp1.MyStruct.c: 3.14159265358979
Speed Controller - ConsoleApp1.MyStruct.a: 22
Speed Controller - ConsoleApp1.MyStruct.b: 15
Speed Controller - ConsoleApp1.MyStruct.c: 3.14159265358979
Altitude Controller - ConsoleApp1.MyStruct.a: 15
Altitude Controller - ConsoleApp1.MyStruct.b: 2
Altitude Controller - ConsoleApp1.MyStruct.c: 3.14159265358979
Speed Controller - ConsoleApp1.MyStruct.a: 22
Speed Controller - ConsoleApp1.MyStruct.b: 15
Speed Controller - ConsoleApp1.MyStruct.c: 3.14159265358979
123123.12