检查变量是否为NULL

Cod*_*eee 2 vb.net variables null pdfsharp

我正在使用PDFSharp开展一个项目.可悲的是,作为VB.Net开发人员,他们提供的示例是用C#编写的.我遇到了检查变量是否存在的问题null.

在C#上,代码声明如下

PdfDictionary resources = page.Elements.GetDictionary("/Resources");
  if (resources != null) 
  'do stuff here
Run Code Online (Sandbox Code Playgroud)

我有第二行的问题,

if(resources!= null)

到目前为止,这是我在VB上所做的,我也从sLaks 读过这个博客.

昏暗的资源如新的PdfDictionary?()

但它给了我一些错误.

简单地设置资源以nothing产生其默认值,可以是int,或者无论如何.我希望它与NULL进行比较.
这是完整的代码.

All*_*sen 6

如果你做了:

Dim resources As New PdfDictionary?()

然后资源将不会是什么,因为你只是将它实例化为某种东西.

你可能会追求的是什么

Dim resources As PdfDictionary = page.Elements.GetDictionary("/Resources")
  IF resources IsNot Nothing THEN
  'do stuff
Run Code Online (Sandbox Code Playgroud)