Guest User

Untitled

a guest
Jun 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. class Foo {
  2. Bar? b;
  3. Bar b2;
  4. Foo() {
  5. b.DoSomething(); //valid, but will cause exception
  6. b2.DoSomething(); //?
  7. }
  8. }
  9.  
  10. String s = mayBeNull?.toString() ?: "null";
  11.  
  12. if (myObj)
  13. {
  14. // in this scope, myObj is non-nullable, so can be used
  15. }
  16.  
  17. if (SomeMethodReturningANullable() into anotherObj)
  18. {
  19. // anotherObj is non-nullable, so can be used
  20. }
  21.  
  22. string message = GetMessage() into m ? m : "No message available";
  23.  
  24. string message = GetMessage() or "No message available";
  25.  
  26. class SpecSharpExampleClass
  27. {
  28. private string! _nonNullableExampleField;
  29.  
  30. public SpecSharpExampleClass(string s)
  31. : _nonNullableExampleField(s)
  32. {
  33.  
  34. }
  35. }
  36.  
  37. b?->DoSomething();
Add Comment
Please, Sign In to add comment