15 anonymous methods, partial types and nullable types

962 views

Published on

Published in: Technology, Health & Medicine
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
962
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

15 anonymous methods, partial types and nullable types

  1. 1. Anonymous Methods,Partial Types and Nullable Types Programming in C# tnngo2@gmail.com
  2. 2. Anonymous Methods
  3. 3. Anonymous Methods an inline nameless block of code.
  4. 4. Features accept parameters ref, out, generic type cannot include jump statements such as goto and break
  5. 5. Benefits No separate named methods Reduced number of methods Better understanding
  6. 6. Implementation Anonymous methods are not given any return type Anonymous methods are not prefixed with access modifiers https://gist.github.com/2586919
  7. 7. Referencing multiple anonymous methods https://gist.github.com/2586945
  8. 8. Passing parameters https://gist.github.com/2586982
  9. 9. Partial Types
  10. 10. Partial Types indicates that other parts of the class, struct or interface can be defined in different files or namespaces. All the parts will be formed to the final type at compile time.
  11. 11. Partial type? working on large projects, multiple programmers work on one class. working with automatically generated source, code can be added to the class without modifying the source file.
  12. 12. Implementation Each of the partial parts of the code must have the same access modifier if a part of code is declared as abstract and others are declared as public => the entire code is considered abstract. Same as sealed class. https://gist.github.com/2592542
  13. 13. Implementation (cont.) Partial Class https://gist.github.com/2592720
  14. 14. Question
  15. 15. Question
  16. 16. Nullable Types
  17. 17. Nullable types? Before C# 2.0, only reference type could be null
  18. 18. Nullable types Null values can be defined for the value types. instance of the System.Nullable<T> struct.
  19. 19. Implementation Nullable types have two properties: HasValue Value can also use the == and != operators if (x != null) y = x; https://gist.github.com/2592834
  20. 20. Implementation (cont.) Nullable types in Expression https://gist.github.com/2592857
  21. 21. ?? Operator assign a nullable type to a non-nullable type. https://gist.github.com/2592875

×