VB.NET: Null reference with an Interface
I have a null reference warning. Dummy code as follows:
Dim poo As IEnumPooTypes
Toilet.GetPooInBowl(poo)
The variable 'Poo' says it may re开发者_StackOverflow社区sult in an object reference not set error but I cannot use the 'New' keyword with an instance. How do I make the warning go away?
You can't instantiate an interface if IEnumPooTypes
is an interface. The I
is implying that it is an interface. You need a concrete implementation of IEnumPooTypes
.
VB.NET only gives you ByVal
(which is an in parameter) and ByRef
(which is an inout parameter). But I think you want to use poo as an out parameter. In this case you need to annotate the declaration with <System.Runtime.InteropServices.Out( )> ByRef
(you can if course import System.Runtime.InteropServices
and write <Out()> ByRef
).
精彩评论