开发者

VB.NET: Null reference with an Interface

开发者 https://www.devze.com 2023-02-19 07:10 出处:网络
I have a null reference warning. Dummy code as follows: Dim poo As IEnumPooTypes Toilet.GetPooInBowl(poo)

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消