SYSTEM.DATA.SQLTYPES // the following lines will compile without

SYSTEM.DATA.SQLTYPES // the following lines will compile without error // but will cause a runtime error Console.WriteLine(d.CompareTo( asdfasdf )); // this will cause a runtime error too Console.WriteLine(d.CompareTo(4.5)); // and so will thisConsole.WriteLine(d.CompareTo(s)); // this will work as expected Console.WriteLine(d.CompareTo((SqlDouble)s); The purpose of CompareTo is to determine the relative value of the instance of a SqlType to the obj. It is meant to be used to order objects. A 0 return value from CompareTomeans objis equal in value to the instance of SqlType. A positive return value means obj is greater in value than the instance of SqlType, and negative means the opposite. Each SqlType is a value type and has all the behaviors of any other value type. The CLR uses value types to represent primitive types like ints and floats. The memory for each is allocated in place, not on the heap, unless it is a member of reference type. The important thing about value types for methods used to implement stored procedures, functions, or triggers is that they do not have a null representation. See Appendix A for a discussion of value types. A SqlType also has the ability to represent a null value, which none of value types in the base class library of the CLR can do. It is important to understand how a SqlType represents a null because this behavior is probably quite different from what you are used to with value types. Every SqlType implements INullable, which has a single property named IsNull. In addition, a SqlType has a public static field named Null. The value of this field is an instance of the SqlTypethat is null. The signature of Null for SqlInt32follows. public static readonly SqlInt32 Null; Note that though a SqlType can represent null, it itself cannot be null, because it is a value type. This means it cannot be compared to null; doing this will always produce a compile-time error. The following code fragment illustrates this. SqlBoolean b = new SqlBoolean(false); // this will produce a compile-time error if(b == null) { Console.WriteLine( b is null ); }

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.