2008年3月6日

[Reading Notes]Reading notes for [Programming C# 3.0, 5th Edition] - 1

Structures

  • Structure is a lightweight alternative to class
  • Structure is of Value type(Which means it requires boxing/unboxing when transform value type to reference type and is created in the stack rather then the heap)
  • Not fully supports inheritance(can inherts only from an object and is implictily sealed)
  • Can not have default constructor nor destructor
  • From [From Java to C#:A developer's Guide] Charapter 26.3,You should choose to use a struct rather than a class for performance reasons. If you are writing a class that:
    • represents a small data structure with few data members, and

    • does not require the use of inheritance, and

    • it is convenient for it to be a value type instead of a reference type

  • Being a value type, an assignment results whole struct's value to be copied over, this might cause performance issues.

  1. Serializable & MarshelByRefObj
    1. A object marked as [Serializable] is passed by value.
    2. A object inherits from MarshelByRefObj is passed by reference, which means, when deserializing, client gets a proxy rather then an object.
  2. LINQ to SQL - About Data Corruption
  • [Chapter 15.2, LINQ to SQL Fundamentals]...LINQ ensures that multiple retrievals of a database record are represented by the same object instance; this makes it much harder for the aforementioned scenario to occur......" that would be reflected in Joe's representation of the object—they are looking at the same data, not at independent snapshots...
    • What if they are accessing the data from different process (can't be same object if LINQ does not provide an independent mempry storage) ? is the above stetments still sustain ? Require further tests.

沒有留言:

Blog Archive

About Me