如何将observablecollection放入列表 [英] how to put observablecollection in List

查看:77
本文介绍了如何将observablecollection放入列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我想将observablecollection放入List< string>像这样:

Hello
I want to put observablecollection into the List<string> like this :

<pre lang="cs">List<string> test = new List<string>();<br />
          foreach (CheckInData coll in CheckInCollection)<br />
          {<br />
              for (int i = 0; i < _CheckInCollection.Count; i++)<br />
              {<br />
               test.Add(coll.RoomNumber[i].ToString());<br />
              }<br />
              <br />
          }</pre><br />


但它仅将集合的第一个字符作为示例,例如,有2424个测试内容将仅为2个.
请任何人帮助我

这是我的收藏集:


but its only put the first character of collection for example there is 2424 test content will be only 2.
Please help me anybody

This is my Collection:

<pre lang="cs">ObservableCollection<CheckInData> _CheckInCollection = new ObservableCollection<CheckInData>();<br />
<br />
   public ObservableCollection<CheckInData> CheckInCollection<br />
   {<br />
       get { return _CheckInCollection; }<br />
   }<br />
   public class CheckInData<br />
   {<br />
       public string RoomNumber { get; set; }<br />
       public decimal Price { get; set; }<br />
       public string Currecny { get; set; }<br />
       public decimal Discount { get; set; }<br />
       public string CheckOut { get; set; }<br />
       public int TotalDay { get; set; }<br />
       public decimal TotalPrice { get; set; }<br />
       public int CheckOutYear { get; set; }<br />
       public int CheckOutMonth { get; set; }<br />
       public int CheckOutDay { get; set; }<br />
       public Boolean IncToday { get; set; }<br />
   }</pre><br />

推荐答案

要在列表中放入什么? RoomNumber?

也许这会帮到您...不是最好的解决方案...但这是一个;)

What do want to put in your List? The RoomNumber?

Maybe this will help you... not the best solution... but it is one ;)

List<string> test = new List<string>();
    foreach (CheckInData checkInData in CheckInCollection)
    {
        if (!test.Contains(checkInData.RoomNumber))
	     test.Add(checkInData.RoomNumber);
    }		
</string></string>




将变量coll重命名为checkInData ...




Renamed the variable coll into checkInData...


这篇关于如何将observablecollection放入列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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