List.Jion
Posted 刘顺利
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了List.Jion相关的知识,希望对你有一定的参考价值。
private void simpleButton1_Click(object sender, EventArgs e) { IList<Channel> list = new List<Channel>(); Channel item = new Channel(); item.ID = 1; item.ChannelName = "1"; list.Add(item); item = new Channel(); item.ID = 2; item.ChannelName = "2"; list.Add(item); IList<Channel1> list1 = new List<Channel1>(); Channel1 item1 = new Channel1(); item1.ID = 1; item1.ChannelName1 = "11"; list1.Add(item1); item1 = new Channel1(); item1.ID = 22; item1.ChannelName1 = "22"; list1.Add(item1); var result = from left1 in list join right1 in list1 on left1.ID equals right1.ID into temp select new { ID = left1.ID, ChannelName = left1.ChannelName, ChannelName1 = temp.Select(t => t.ChannelName1).FirstOrDefault() }; var result1 = list.Join(list1, T1 => T1.ID, T2 => T2.ID, (T1, T2) => new { Name = T1.ChannelName, ID = T1.ID, NickName = T2.ChannelName1 }); this.gridControl1.DataSource = result1; } } public class Channel { private int _ID = 0; private string _ChannelName = ""; /// <summary> /// /// </summary> public int ID { set { this._ID = value; } get { return this._ID; } } /// <summary> /// /// </summary> public string ChannelName { set { this._ChannelName = value; } get { return this._ChannelName; } } public Channel() { } public Channel(int _ID, string _ChannelName) { this.ID = _ID; this.ChannelName = _ChannelName; } } public class Channel1 { private int _ID = 0; private string _ChannelName1 = ""; /// <summary> /// /// </summary> public int ID { set { this._ID = value; } get { return this._ID; } } /// <summary> /// /// </summary> public string ChannelName1 { set { this._ChannelName1 = value; } get { return this._ChannelName1; } } public Channel1() { } public Channel1(int _ID, string _ChannelName1) { this.ID = _ID; this.ChannelName1 = _ChannelName1; } }
以上是关于List.Jion的主要内容,如果未能解决你的问题,请参考以下文章