PC Review


Reply
Thread Tools Rate Thread

Bug in DirectCast() ?

 
 
Guido Kraus
Guest
Posts: n/a
 
      30th Mar 2004
I tried this VB.NET 2003 (.Net runtime 1.1):

Dim o As Object = DirectCast(Nothing, HashTable)
If IsNothing(o) Then
Debug.WriteLine("Nothing")
Else
Debug.WriteLine("Something")
End If

Guess what: o is not Nothing!
Is this a bug or a feature? By the way: CType(Nothing, HashTable) returns
Nothing as I would expect.

Guido


 
Reply With Quote
 
 
 
 
Bill McCarthy
Guest
Posts: n/a
 
      30th Mar 2004
hi Guido,

recheck your code. I tested it and cannot reproduce. I get o is Nothing.


Bill.


"Guido Kraus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I tried this VB.NET 2003 (.Net runtime 1.1):
>
> Dim o As Object = DirectCast(Nothing, HashTable)
> If IsNothing(o) Then
> Debug.WriteLine("Nothing")
> Else
> Debug.WriteLine("Something")
> End If
>
> Guess what: o is not Nothing!
> Is this a bug or a feature? By the way: CType(Nothing, HashTable) returns
> Nothing as I would expect.
>
> Guido
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Mar 2004
* "Guido Kraus" <(E-Mail Removed)> scripsit:
> I tried this VB.NET 2003 (.Net runtime 1.1):
>
> Dim o As Object = DirectCast(Nothing, HashTable)
> If IsNothing(o) Then
> Debug.WriteLine("Nothing")
> Else
> Debug.WriteLine("Something")
> End If
>
> Guess what: o is not Nothing!
> Is this a bug or a feature? By the way: CType(Nothing, HashTable) returns
> Nothing as I would expect.


I am not able to repro that in .NET 1.1, VB.NET 2003.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Bill McCarthy
Guest
Posts: n/a
 
      30th Mar 2004
Hi Guido,

Yeh, I get the same in the watch window, but I still get the result to be
Nothing when actually run:
e.g:

Console.Writeline( DirectCast(Nothing, Hashtable) Is Nothing)

returns True.

What does your watch window say for :
DirectCast(Nothing, Hashtable) Is Nothing




"Guido Kraus" <(E-Mail Removed)> wrote in message
news:OE%(E-Mail Removed)...
> Hi Bill,
>
> I made a screenshot of my Watch window (I have the German version of VS.NET
> but I everybody will understand it).
>
> Guido
>
> "Bill McCarthy <no spam>" <bill_mcc &#64; iprimus.com.au> schrieb im
> Newsbeitrag news:e6$$(E-Mail Removed)...
> > hi Guido,
> >
> > recheck your code. I tested it and cannot reproduce. I get o is Nothing.
> >
> >
> > Bill.
> >
> >
> > "Guido Kraus" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > I tried this VB.NET 2003 (.Net runtime 1.1):
> > >
> > > Dim o As Object = DirectCast(Nothing, HashTable)
> > > If IsNothing(o) Then
> > > Debug.WriteLine("Nothing")
> > > Else
> > > Debug.WriteLine("Something")
> > > End If
> > >
> > > Guess what: o is not Nothing!
> > > Is this a bug or a feature? By the way: CType(Nothing, HashTable)

> returns
> > > Nothing as I would expect.
> > >
> > > Guido
> > >
> > >

> >
> >

>
>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      30th Mar 2004
Hi Guido,
Dim o As Object = DirectCast(Nothing, Hashtable)
Dim m As Object = CType(Nothing, Hashtable)
If m Is o Then
MessageBox.Show("both the same")
End If

both the same is showed (and they are nothing)

Cor


 
Reply With Quote
 
Guido Kraus
Guest
Posts: n/a
 
      30th Mar 2004
Hi Bill,

you are right.
DirectCast(Nothing, Hashtable) Is Nothing correctly returns Nothing and the
example I gave also works correctly. However, the watch window and the
variable tooltips obviously have a problem because they display {Length = 0}
instead of Nothing.

Guido

"Bill McCarthy <no spam>" <bill_mcc &#64; iprimus.com.au> schrieb im
Newsbeitrag news:(E-Mail Removed)...
> Hi Guido,
>
> Yeh, I get the same in the watch window, but I still get the result to be
> Nothing when actually run:
> e.g:
>
> Console.Writeline( DirectCast(Nothing, Hashtable) Is Nothing)
>
> returns True.
>
> What does your watch window say for :
> DirectCast(Nothing, Hashtable) Is Nothing
>
>
>
>
> "Guido Kraus" <(E-Mail Removed)> wrote in message
> news:OE%(E-Mail Removed)...
> > Hi Bill,
> >
> > I made a screenshot of my Watch window (I have the German version of

VS.NET
> > but I everybody will understand it).
> >
> > Guido
> >
> > "Bill McCarthy <no spam>" <bill_mcc &#64; iprimus.com.au> schrieb im
> > Newsbeitrag news:e6$$(E-Mail Removed)...
> > > hi Guido,
> > >
> > > recheck your code. I tested it and cannot reproduce. I get o is

Nothing.
> > >
> > >
> > > Bill.
> > >
> > >
> > > "Guido Kraus" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > I tried this VB.NET 2003 (.Net runtime 1.1):
> > > >
> > > > Dim o As Object = DirectCast(Nothing, HashTable)
> > > > If IsNothing(o) Then
> > > > Debug.WriteLine("Nothing")
> > > > Else
> > > > Debug.WriteLine("Something")
> > > > End If
> > > >
> > > > Guess what: o is not Nothing!
> > > > Is this a bug or a feature? By the way: CType(Nothing, HashTable)

> > returns
> > > > Nothing as I would expect.
> > > >
> > > > Guido
> > > >
> > > >
> > >
> > >

> >
> >
> >

>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      30th Mar 2004
Guido,

I remember me that shortly ago Jay B. Harlow has told something about this
windows

I found the article here

http://tinyurl.com/2lrb4

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Mar 2004
* "Guido Kraus" <(E-Mail Removed)> scripsit:
> you are right.
> DirectCast(Nothing, Hashtable) Is Nothing correctly returns Nothing and the
> example I gave also works correctly. However, the watch window and the
> variable tooltips obviously have a problem because they display {Length = 0}
> instead of Nothing.


Yep. The watch window and the tooltips don't always show the right
data.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DirectCast kimiraikkonen Microsoft VB .NET 9 11th Jan 2008 08:28 PM
directcast =?Utf-8?B?aXdkdTE1?= Microsoft VB .NET 1 20th Sep 2005 02:56 AM
DirectCast in .NET 2.0 Sahil Malik Microsoft C# .NET 10 4th Jan 2005 01:31 PM
DirectCast Merlin Microsoft VB .NET 3 17th Mar 2004 05:18 PM
Re: DirectCast Mattias Sjögren Microsoft C# .NET 0 17th Aug 2003 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 PM.