code_junkie

Why is “null” present in C# and java?

Nov 11th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. static string AcceptNotNullObject(object! s)
  2. {
  3. return s.ToString();
  4. }
  5.  
  6. MyResource resource;
  7. try
  8. {
  9. resource = new MyResource();
  10. //
  11. // Do some work
  12. //
  13. }
  14. finally
  15. {
  16. if (resource != null)
  17. resource.Close();
  18. }
  19.  
  20. let counter = ref 0;;
  21. let next_counter_value () = (counter := !counter + 1; !counter);;
  22.  
  23. type distributed_computation_result = NotYetAvailable | Result of float;;
  24. let print_result r = match r with
  25. | Result(f) -> Printf.printf "result is %fn" f
  26. | NotYetAvailable -> Printf.printf "result not yet availablen";;
  27.  
  28. class A {
  29. B fieldb;
  30. }
  31.  
  32. class B {
  33. A fielda;
  34. }
  35.  
  36. A a = new A() // a.fieldb is null
  37. B b = new B() { fielda = a } // b.fielda isnt
  38. a.fieldb = b // now it isnt null anymore
Add Comment
Please, Sign In to add comment