USER-DEFINED TYPES AND AGGREGATES double seconds; // third

USER-DEFINED TYPES AND AGGREGATES double seconds; // third sort key byte direction; // 0 for E, 1 for W, fourth sort key public override string ToString() { } public bool IsNull { } public static LDim Null { } public static LDim Parse(SqlString s) { } } Implementing LDim We will now look at implementing the LDim user-defined type, shown in Listing 5-4. It will illustrate most, though not all, of the issues involved in implementing user-defined types. LDimis a user-defined type that is used to represent a linear dimension. It has two properties associated with it: value and units. The units are used to scale the value so that, for example, 1 ft is the same value as 12 in . This sort of data type is widely used in various engineering, architecture, and other disciplines. The basic implementation of LDim is shown in Listing 5-4. Listing 5-4: Basic Implementation of LDim public struct LDim { private double value; private string units; // rest of implementation } It is a requirement that a public CLR class must be used to implement a user-defined type. Note that in C# and VB.NET, a struct is a CLR class that is derived from System.ValueType. There are number of trade-offs to be made in choosing a class that derives from System.ValueTypeand one that doesn t. These are discussed in MSDN and other places. This basic implementation of LDimcan maintain the state of a dimension.

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

Bookmark the permalink.

Comments are closed.