声明未知数量的图像阵列问题 [英] declaring unknown number of image array problem
本文介绍了声明未知数量的图像阵列问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一段代码,将桌面图像保存到未知数量的图像阵列中.但是当我运行下面的代码时,它显示了此问题:对象引用未设置为对象的实例.".我知道说我需要这样声明图像:image [] i = new image [100],但是我不知道我的图像是100个或更多或更少.请帮助我.
代码:
private int num; private Image[] i; private void timer1_Tick(object sender, EventArgs e) { SendKeys.Send("{PRTSC}"); i[num] = Clipboard.GetImage(); num++; }
解决方案
代替数组,请考虑将其用作通用列表: ^ ].现在使用添加 [ code :
private int num; private Image[] i; private void timer1_Tick(object sender, EventArgs e) { SendKeys.Send("{PRTSC}"); i[num] = Clipboard.GetImage(); num++; }
Thanks.解决方案Instead of an array, consider using as generic list: List<t> Class[^]. Now with Add[^] method you can add the necessary items and the list expands automatically.
这篇关于声明未知数量的图像阵列问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文