fork download
  1. using System;
  2.  
  3. class Test{
  4. public struct Ref{
  5. public delegate int GetD<T>(T A);
  6. public delegate void SetD<T, VT>(ref T trg, VT val);
  7. public struct RefIn<T, VT>{
  8. public readonly GetD<T> Get;
  9. public readonly SetD<T, VT> Set;
  10. public RefIn(GetD<T> g, SetD<T, VT> s){
  11. Get = g;
  12. Set = s;
  13. }
  14. }
  15. public static RefIn<T, VT> Wrap<T, VT>(GetD<T> g, SetD<T, VT> s){
  16. return new RefIn<T, VT>(g, s);
  17. }
  18. }
  19. struct Hoge {
  20. public int A;
  21. }
  22. public static void Main(){
  23. Hoge trg = new Hoge();
  24.  
  25. var wr = Ref.Wrap(
  26. (Hoge t) => t.A,
  27. (ref Hoge t, int v) => t.A = v
  28. );
  29.  
  30. wr.Set(ref trg, 100);
  31. Console.Write( wr.Get(trg) );
  32. }
  33. }
  34.  
Success #stdin #stdout 0.03s 36976KB
stdin
Standard input is empty
stdout
100