USER-DEFINED TYPES AND AGGREGATES Listing 5-9: SQL Server

USER-DEFINED TYPES AND AGGREGATES Listing 5-9: SQL Server Calling ToString create a Table that uses LDim CREATE TABLE Lengths ( Length LDim ) select something from that table the CONVERT function will call ToString on the implementation of LDim SELECT CONVERT(CHAR, Length) FROM Lengths ToString is a virtual function in the System.Object class. Every CLR class inherits System.Object whether or not it is explicitly specified. An implementation of a user-defined type must override this method. ToString returns a string that is considered the lexical representation of the value. Listing 5-10 shows the LDimimplementation of ToString. Listing 5-10: Implementation of ToString public struct LDim : INullable { private double value; private string units; public override string ToString() { // check to see if units is null // if it is this instance is // representing a null if(null == units) { return null ; } return String.Format( {0:d} {s} , value, units); } // rest of implementation } Note that when LDimis representing a null, it returns the string null . Otherwise, it formats a string that consists of a number, whitespace, and the unitsstring. Implementing Parse Parseis the functional complement of ToString. It must be a public static method. It takes a string as input and converts it into an instance of the

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

Bookmark the permalink.

Comments are closed.