15 anonymous methods, partial types and nullable types
TRANSCRIPT
![Page 2: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/2.jpg)
Anonymous Methods
![Page 3: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/3.jpg)
Anonymous Methods an inline nameless block of code.
![Page 4: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/4.jpg)
Features accept parameters ref, out, generic type cannot include jump statements such as goto and break
![Page 5: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/5.jpg)
Benefits No separate named methods Reduced number of methods Better understanding
![Page 6: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/6.jpg)
Implementation Anonymous methods are not given any return type Anonymous methods are not prefixed with access modifiers
https://gist.github.com/2586919
![Page 7: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/7.jpg)
Referencing multiple anonymous methods https://gist.github.com/2586945
![Page 9: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/9.jpg)
Partial Types
![Page 10: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/10.jpg)
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.
![Page 11: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/11.jpg)
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.
![Page 12: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/12.jpg)
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
![Page 13: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/13.jpg)
Implementation (cont.) Partial Class
https://gist.github.com/2592720
![Page 14: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/14.jpg)
Question
![Page 15: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/15.jpg)
Question
![Page 16: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/16.jpg)
Nullable Types
![Page 17: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/17.jpg)
Nullable types? Before C# 2.0, only reference type could be null
![Page 18: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/18.jpg)
Nullable types Null values can be defined for the value types. instance of the System.Nullable<T> struct.
![Page 19: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/19.jpg)
Implementation Nullable types have two properties: HasValue Value can also use the == and != operators if (x != null) y = x; https://gist.github.com/2592834
![Page 20: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/20.jpg)
Implementation (cont.) Nullable types in Expression https://gist.github.com/2592857
![Page 21: 15 anonymous methods, partial types and nullable types](https://reader035.vdocuments.site/reader035/viewer/2022062312/554eba12b4c905fb7c8b56d9/html5/thumbnails/21.jpg)
?? Operator assign a nullable type to a non-nullable type. https://gist.github.com/2592875