cp1,cp2,cp3,cp4,cp5有没有初始化,如:
cp1 = new Label();
cp1 = new Label();
解决方案 »
- 小弟做作业,求圆锥体的体积,一个小小的程序,遇见小小的问题啦,小小的我不能解决,希望大师们能耐心传授一下经验!谢谢
- |ZYCWPF| 为RichTextBox添加查找替换功能,为什么我绑定的控件得不到控件对像,而是得到一个int 0 谢谢
- C# 在C#中如何调用API函数SetClipboardData
- 想用c#编写一个小程序以实现检查键盘大小写锁定状态并显示到任务栏或者桌面上,请问如何实现?
- 导出Word文件时,中文乱码!
- C#中如何从字符串"(a + b)/100"中获得计算表达式c = (a + b) / 100
- c# 图片滚动代码
- winform下文本框获取焦点时全选问题
- 为什么 老报错呢
- Duwamish中using的疑问
- 关于发邮件的问题
- datagrid数据更新的问题
中的变量都null
必须初始化
this.cp1 = new System.Windows.Forms.Label();
this.cp2 = new System.Windows.Forms.Label();
this.cp3 = new System.Windows.Forms.Label();
this.cp4 = new System.Windows.Forms.Label();
this.cp5 = new System.Windows.Forms.Label();
this.cp6 = new System.Windows.Forms.Label();而 cp = new Label[19];
cp[0]=cp1;
cp[1]=cp2;
cp[2]=cp3;
cp[3]=cp4;
cp[4]=cp5;是在 InitializeComponent();方法之后调用的
private System.Windows.Forms.Label cp1,cp2,cp3,cp4,cp5;
private System.Windows.Forms.Label[] cp;
然后是这个类的构造函数
InitializeComponent();
SetArrCp();
其中InitializeComponent();方法中有
this.cp1 = new System.Windows.Forms.Label();
this.cp2 = new System.Windows.Forms.Label();
this.cp3 = new System.Windows.Forms.Label();
this.cp4 = new System.Windows.Forms.Label();
this.cp5 = new System.Windows.Forms.Label();
this.cp6 = new System.Windows.Forms.Label();
SetArrCp();方法中
cp = new Label[19];
cp[0]=cp1;
cp[1]=cp2;
cp[2]=cp3;
cp[3]=cp4;
cp[4]=cp5;然后我在另一个方法中这样写的
for(int i=0;i<dmodel.mtotal;i++)
{
cp[i].Text = dmodel[i].PartNumber;
}运行程序执行这个方法说未将对象的一个引用设置到实例。
cp = new Label[19];只是实例化了数组,应该还加一句
cp[1]=new Label();
cp数组所有对象都初始化了吗?