Study notes 70-553 Section 1 part a

posted in: Uncategorized | 0

BronwenWeeGo.jpg

Manage data in a .NET Framework application by using .NET Framework 2.0 system types. (Refer System namespace)
• Value types (bool, byte, char, decimal, double, enum, float, int long, sbyte, short, struct, uint, ulong, ushort)
 
• 
2 categories
 – structs  ( numeric types, bool, user defined)
 – enums 
Derived from System.ValueType.  Cannot contain null. Implicit default constructor that intialises default value. Assigning one valuetype to another copies the contained value.  Stored on stack

• Reference types (object, string, class, delegate, interface)
Store references to the actual data.  Inherits from system.object. Stored  on heap
Delegate – Function pointer.

• Attributes

Associate declarative info with code.  Can be queried at runtime by Reflection.
CLR attributes e.g. [System.Serializable]common ones..
– conditional e.g. [Conditional(“DEBUG”)]– obsolete e.g. [System.Obsolete(“use class B”)]– global e.g. [assembly: AssemblyCompany(“Soul Solutions”)]– attribute usage e.g. [System.AttributeUsage(System.AttributeTargets.All)]Custom Attributes – create a class : System.Attribute.  Give attributes [System.AttributeUsage(System.AttributeTargets.Class |                       System.AttributeTargets.Struct, AllowMultiple = true)  // multiuse attribute]

• Generic types
Increase code reuse and type safety
System.Collections.Generic , System.Colections.ObjectModel
Collections e.g. Dictionary, List, queue, stack – Faster as they prevent boxing/unboxing
Nullable – allows value type as if they could store null
Constraints:
Where T: struct, class – must be a value / ref type
where T: new() – must have public parameter constructor
where t: base – must derive from…
where t: interface – must implement interface
where t: U – t must derive from u
Limitations:
– Can’t derive from ContextBoundObject
– Enum can’t have generic type parameter
– Dynamic methods can’t be generic
– Nested type enclosed in generic type

• Exception classes 
Represents errors that occur during application execution.  Put more specific exceptions first.
Has following features: Human readable text describing error, stored in Message.  State of the call stack in the StackTrace.
Predefined – SystemException
User defined derived from Application Exception

• Boxing and UnBoxing 
Enables value types to be treated as objects.  Packages inside instance of Object, allowing storage in garbage collection heap.

• TypeForwardedToAttribute class
Allows moving of assemblies without having to recompile apps using your assemblies.
E.g. Original Assembly A1, Class C1
Want to split to assemblie A2
How to:
1. Crate A2, move C1 into it
2. In A1 remove c1 code and add [assembly:TypeForwardedToAttribute(typeof(C1))]3. Compile A2
4. Compile A1 with reference – /reference option