Guest User

Untitled

a guest
May 28th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // Assignment compatibility.
  2. string str = "test";
  3. // An object of a more derived type is assigned to an object of a less derived type.
  4. object obj = str;
  5.  
  6. // Covariance.
  7. IEnumerable<string> strings = new List<string>();
  8. // An object that is instantiated with a more derived type argument
  9. // is assigned to an object instantiated with a less derived type argument.
  10. // Assignment compatibility is preserved.
  11. IEnumerable<object> objects = strings;
  12.  
  13. // Contravariance.
  14. // Assume that the following method is in the class:
  15. // static void SetObject(object o) { }
  16. Action<object> actObject = SetObject;
  17. // An object that is instantiated with a less derived type argument
  18. // is assigned to an object instantiated with a more derived type argument.
  19. // Assignment compatibility is reversed.
  20. Action<string> actString = actObject;
Add Comment
Please, Sign In to add comment