使用属性返回数组 [英] Return an Array using a Property

查看:61
本文介绍了使用属性返回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我创建了一个类,其中正在读取数据库并填充数组.数组加载正常.
然后,我从另一个Windows窗体中调用该数组的内容.我遇到的问题是,当我调用填充列表框时所看到的所有表单都是列表框内的"Double [] Array"而不是数组的内容.
再次感谢!


这是我的财产:


Hi All,
I have created a class in which I am reading through a DB and populating an array. The array gets loaded fine.
I am then calling for the contents of that array from another Windows Form. The problem that I am having is that when I call to populate the list box in the form all I see is "Double[] Array" inside of the listbox instead of the contents of the array.
Thanks again!


This is my property:


public double[] My_Array
{
    get
   {
       return priv_rd_dblTestArray;
    }
    set
    {
       priv_rd_dblTestArray = value;
    }


 }




这是对属性值的调用:

listBox2.Items.Add(eCirc_Read.My_Array);


这是列表框内的结果:

"Double [] Array"




This is the call to the property values:

listBox2.Items.Add(eCirc_Read.My_Array);


This is the result inside of the listbox:

"Double[] Array"

推荐答案

那是因为列表框显示了字符串,如果没有覆盖,则数组的ToString() 方法将返回其类型.提供了.

尝试通过以下方式更新列表框:

That''s because a listbox shows strings, and the ToString() method for your array returns its'' type if no override is provided.

Try updating your listbox this way:

foreach(double value in eCirc_Read.My_Array)
{
    listBox2.Items.Add(Convert.ToString(value));
}


这篇关于使用属性返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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