Doug Stiers wrote:
I'm trying to determine the type of a datareader value. Why cant I do it
like this?
if (rdr.GetValue(0).GetType() is Guid || rdr.GetValue(0).GetType() is
Int32)
The "is" operator works for instances: it will tell you if a
particular object is assignment compatible with the instance of the
type on the right (ie, is an instance of that type, or is an instance
of a descendant type).
GetType() returns a System.Type instance. A Type instance is a runtime
description of a compile-time type; it is not an instance of the type,
nor is it the compile-time type itself.
You should be able to do what you want with either
Type FirstValueType = rdr.GetValue(0).GetType();
if (FirstValueType == typeof(Guid) ||
FirstValueType == typeof(Int32))
// or
object FirstValue = rdr.GetValue(0);
if (FirstValue is Guid || FirstValue is Int32)
--
..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.