我已经创建了一个返回列表的函数. [英] I have Created a function which return a list.

查看:96
本文介绍了我已经创建了一个返回列表的函数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个返回IList的方法,

列表返回一行,
所以,我想在不同的标签中设置列表值...

这是我的代码.

Hello ALL,

I have created a method which return a IList,

List return a one row,
So ,I want to set the list value in different label...

Here is my code..

if (mediationinfolist.Count >= 1)
       {
           mediationinfo.Mediationinfolist = mediationinfolist;
       }

       for (int i = 1; i <= mediationinfo.Mediationinfolist.Count; i++)
       {
           lblMediationDate.Text = Functions.GetDate(mediationinfo.Mediationinfolist[i].MediationDate, 7);



}

它显示索引超出范围异常.

请给我解决方案..



}

it show index out of range exception.

please give me solution..

推荐答案


运行循环 for (int i = 0; i <= mediationinfo.Mediationinfolist.Count-1; i++).

将来,请尝试调试代码,确保可以自己找到解决方案.
Run your loop as
for (int i = 0; i <= mediationinfo.Mediationinfolist.Count-1; i++).

In the future, try and debug your code and I''m sure you will be able to find the solution yourself.


请注意以下有关数组,列表和索引值的内容
1. 索引始终从0而不是1开始.
2.用 0 计数计数器,然后循环直到 count-1

首先阅读理论部分,然后进行编码,这是基本的事情.
编程愉快.
Note following points about Array, list and index values
1. Index start with always 0 not 1.
2. Srart counter with 0 and loop until count-1

Read theory part first and then go for coding this is basic thing.
Happy programming.


按照另一位专家的建议,我尝试将i++更改为++i,令我惊讶的是,发现它的运行速度相当快(对于循环体,当然).另外,有人说<"条件更快.我还将改善命名;一个字符的名称确实很糟糕.因此,要改善显示我的Abhinav的解决方案(我认为是正确的),请执行以下操作:


Following the advice by one other expert, I tried to change i++ to ++i and, to my surprise, found that it works considerably faster (for small footprint in the loop body, of course). Also, some say the ''<'' condition is faster. I''ll also improve naming; one-character names are really bad. So to improve the solution shown my Abhinav (which I credit as correct), do:


for (int index = 0; index < mediationInfo.MediationInfoList.Count; index++) {/*...*/}



使用调试器!

祝你好运,

—SA



Use the debugger!

Good luck,

—SA


这篇关于我已经创建了一个返回列表的函数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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