如何检查System :: Collections:ArrayList是否为空/ nullptr / null? [英] How do I check if System::Collections:ArrayList is empty / nullptr / null?

查看:326
本文介绍了如何检查System :: Collections:ArrayList是否为空/ 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()以检查集合是否为空



我会建议过去:



引用和指针变量之间的差异



何时使用引用VS指针


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?

解决方案

% 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

这篇关于如何检查System :: Collections:ArrayList是否为空/ nullptr / null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆