使用Linq读取第一个和最后一个项目组合框 [英] Read First and Last Item ComboBox with Linq

查看:75
本文介绍了使用Linq读取第一个和最后一个项目组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...
请问如何使用linq获得第一个和最后一个组合框
非常感谢

Hi...
excuse me.how do i can get first and last item combobox with linq
very Thanks

推荐答案

为什么使用linq?

Why linq?

String first = (From item In ComboBox1.Items).FirstOrDefault;
String last = (From item In ComboBox1.Items).LastOrDefault;



正常的方法难道不是很容易吗?!



Isn''t the normal way easier?!

String first = ComboBox1.Items[0];
String last = ComboBox1.Items[ComboBox1.Items.Count-1];


Linq和ComboBox不起作用好吧.

尝试这种方法.
Linq and ComboBox dont work well.

Try this approach.
ComboBox cb = new ComboBox();
List<object> list = cb.Items.Cast<object>().ToList();
object first = list.First();
object last = list.Last();



祝你好运!



Good luck!


为什么在地球上应该是LINQ?这就是myComboBox.Items[0]myComboBox.Items[myComboBox.Items.Count-1]

唯一原因,我可以看到有人告诉您这样做,但是我们不必回答此类问题;在这种情况下,那个人应该问CodeProject,而不是你.就是这样.

—SA
Why on Earth it should be LINQ? This is simply myComboBox.Items[0] and myComboBox.Items[myComboBox.Items.Count-1]

The only reason I can see it is somebody told you to do that, but we don''t have to answer such Questions; in this case that person should ask CodeProject, not you. This is how it works.

—SA


这篇关于使用Linq读取第一个和最后一个项目组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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