IMPLEMENTING LDIM Implementing INullable INullable is an interface

IMPLEMENTING LDIM Implementing INullable INullable is an interface defined in the System.Data.Sql namespace. Implementing it is straightforward; it has a single, read-only property named IsNull that returns a System.Boolean (bool in C# or Boolean in VB.NET). Some thought has to be put into how a user-defined type will internally represent a null value. A simple way to do this is to add a field that stores a flag to indicate whether or not the value is null. This is shown in Listing 5-5. Listing 5-5: Simple Implementation of INullable public struct LDim : INullable { private double value; private string units; private bool valueNotNull; // read-only property public bool IsNull { get { return !valueNotNull;} } // rest of implementation } This implementation of IsNull is taking advantage of the fact that the fields of a struct are always initialized to zero. This means that the parameterless constructor for LDimwill be initialized to be a null value. That is the reason for the double negative that appears in the IsNull property implementation. This way of implementing IsNullhas costs in space. One cost is in the memory taken up by the valueNotNull field, but in many cases this may be of no significance. The other cost is in the space taken up on the disk to store an instance of an LDim type, which will be multiplied by the number of rows in a database that contain LDim columns. There are two ways to mitigate this. If the class implements IBinarySerialize, it can choose a more compact way to save a null instance. For convenience, this implementation ensures that when a new LDimis created using new LDim(), it will in fact be a null representation. Because of this, the test for null requires a double negative. The other way is to encode the null representation in the existing fields of LDim. This will make it easier to implement IBinarySerialize, which

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Bookmark the permalink.

Comments are closed.