[Mono-list] Boxed types in C#

Jaroslaw Kowalski jarek@atm.com.pl
Wed, 12 Jun 2002 00:23:38 +0200 (CEST)


How about using SqlInt32, SqlString, ... to hold the data? They all
provide typed Null (i.e. SqlIn32.Null, SqlString.Null, and reasonable
implicit conversions).

Jarek

On Tue, 11 Jun 2002, Sergey Chaban wrote:

> > in C# it seems that the System.Int32 type is 
> > a value type and hence cannot hold null at all. It also seems that 
> > although you can box it into a variable of type "object", there's no way 
> > to express the *type* of the object in C#. 
> 
> Use generic ValueType class to pass boxed values around.
> (Or, alternatively, use one of the interfaces implemented by those
> wrapper structures, such as IConvertible).
> 
> Something like this:
> 
> public ValueType this[int i] {
>     get {return mytable[i];}
> }
> 
> public void FooBar() {
>     bool ok = MyVal is Int32; //or MyVal != null
>     int i = (ok ? (int)MyVal : 0);
> }
> 
> Or write your own wrapper class similar to Java Integer,
> but with implicit conversion operators.
> 
> Sergey
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>