How do I check if System::Collections:ArrayList is empty / nullptr / null?

丶灬走出姿态 提交于 2020-01-04 13:42:04

问题


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 passing queue_tx as a parameter to a function and there's supposed to be the possibility of this parameter not being set (or being set to nullptr).

The compiler throws '!=' : no conversion from 'System::Collections::ArrayList' to 'nullptr'.

How do I do this?


回答1:


% defines a reference variable this is why it cannot be null

if 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 empty

I would recommend going over:

the difference between reference and pointer variables

When to use a Reference VS Pointers




回答2:


It is quite impossible for a T% to be null.



来源:https://stackoverflow.com/questions/17549506/how-do-i-check-if-systemcollectionsarraylist-is-empty-nullptr-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!