如何在 vb.net 中分配非空条件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24941778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to assign not null condition in vb.net?
提问by NarasimhaKolla
i am working on windows8 vb.net mobile application in that application i am checking not null conditions.here below i have attaching the code file.
我正在该应用程序中处理 windows8 vb.net 移动应用程序,我正在检查非空条件。下面我附上了代码文件。
If JobEventAllDetailsSortnew.Item(value).EventText() IsNot Nothing _
And JobEventAllDetailsSortnew.Item(value).ReasonCodeDesc() IsNot Nothing Then
mEventNotes = "Event text: " + JobEventAllDetailsSortnew.Item(value).EventText() + _
"\nReason: " + JobEventAllDetailsSortnew.Item(value).ReasonCodeDesc()
ElseIf JobEventAllDetailsSortnew.Item(value).EventText().Trim() IsNot Nothing Then
mEventNotes = "Event text: " + JobEventAllDetailsSortnew.Item(value).EventText()
Else
mEventNotes = JobEventAllDetailsSortnew.Item(value).EventText().Trim() + _
"\n" + JobEventAllDetailsSortnew.Item(value).ReasonCodeDesc().Trim()
End If
Please give me any suggestion how to write not null conditions in vb.net?
请给我任何建议如何在 vb.net 中编写非空条件?
回答by ZeroBased_IX
You can do it a few ways, you could do:
你可以通过几种方式做到这一点,你可以这样做:
Value <> Nothing
Or
或者
If Not String.IsNullOrEmpty(JobEventAllDetailsSortnew.Item(value).EventText())
End If
To name a couple of ways.
列举几种方式。
http://msdn.microsoft.com/en-us/library/system.string.isnullorempty(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.string.isnullorempty(v=vs.110).aspx

