code_junkie

Do generic interfaces in C# prevent boxing? (.NET vs Mono performance)

Nov 11th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public interface IMyInterface
  2. {
  3. void MyMethod(object arg);
  4. }
  5.  
  6. public class MyClass1 : IMyInterface
  7. {
  8. public void MyMethod(object arg)
  9. {
  10. MyObject obj = (MyObject) arg;
  11. // do something with obj...
  12. }
  13. }
  14.  
  15. public class MyClass2 : IMyInterface
  16. {
  17. public void MyMethod(object arg)
  18. {
  19. byte[] obj = (byte[]) arg;
  20. // do something with obj...
  21. }
  22. }
  23.  
  24. public interface IMyInterface<T>
  25. {
  26. void MyMethod(T arg);
  27. }
  28.  
  29. public class MyClass1 : IMyInterface<MyObject>
  30. {
  31. public void MyMethod(MyObject arg)
  32. {
  33. // typecast no longer necessary
  34. //MyObject obj = (MyObject) arg;
  35. // do something with arg...
  36. }
  37. }
  38.  
  39. public class MyClass2 : IMyInterface<byte[]>
  40. {
  41. public void MyMethod(byte[] arg)
  42. {
  43. // typecast no longer necessary
  44. //byte[] obj = (byte[]) arg;
  45. // do something with arg...
  46. }
  47. }
  48.  
  49. void Bla<T> (T a, T b);
Add Comment
Please, Sign In to add comment