本文介绍了如何将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 />
推荐答案
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放入列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!