如何检查System :: Collections:ArrayList是否为空/ nullptr / null? [英] How do I check if System::Collections:ArrayList is empty / nullptr / null?
问题描述
我想知道在C ++ / CLI中如何检查ArrayList是否存在。
System :: Collections :: ArrayList%queue_tx
我试过 if(nullptr!= queue_tx){queue_tx.Add(msg); }
但是没有工作。我将 queue_tx
作为参数传递给一个函数,并且应该有这个参数不被设置的可能性(或被设置为 nullptr
)。
编译器抛出'!=':没有从'System :: Collections :: ArrayList' 'nullptr'
。
如何做到这一点?
%
定义引用变量,这是为什么它不能为空
已经这样声明了ArrayList:
System :: Collections :: ArrayList ^ queue_tx
那么你的nullptr检查是可能的,并且有一个意义
code> queue_tx.Count()以检查集合是否为空
我会建议过去:
I'd like to know how in C++/CLI it is possible to check whether an ArrayList is existent.
System::Collections::ArrayList %queue_tx
I tried
if ( nullptr != queue_tx ) { queue_tx.Add(msg); }
but that didn't work. I'm passingqueue_tx
as a parameter to a function and there's supposed to be the possibility of this parameter not being set (or being set tonullptr
).The compiler throws
'!=' : no conversion from 'System::Collections::ArrayList' to 'nullptr'
.How do I do this?
解决方案
%
defines a reference variable this is why it cannot be nullif you would have declared the ArrayList like this:
System::Collections::ArrayList^ queue_tx
then your nullptr check would be possible and have a meaning
otherwise just use the
queue_tx.Count()
to check if the collection is emptyI would recommend going over:
the difference between reference and pointer variables
When to use a Reference VS Pointers
这篇关于如何检查System :: Collections:ArrayList是否为空/ nullptr / null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!