我有以下程序:
void Main()
{
List<Online_video_for_programmers> current_year_videos = new List<Online_video_for_programmers>()
{
new Online_video_for_programmers
{
video_name="websocket for fortran programmers",
season=2,
seasontype=1,
year=2012
},
new Online_video_for_programmers
{
video_name="cross site scripting for facebook addicts",
season=3,
seasontype=2,
year=2012
},
new Online_video_for_programmers
{
video_name="Artificial intelligence for self aware robots",
season=1,
seasontype=1,
year=2012
}
,
new Online_video_for_programmers
{
video_name="Artificial intelligence for self aware robots",
season=3,
seasontype=1,
year=2012
},
new Online_video_for_programmers
{
video_name="Artificial intelligence for adavanced robots",
season=5,
seasontype=1,
year=2012
},
new Online_video_for_programmers
{
video_name="Yoga for programmers",
season=2,
seasontype=2,
year=2012
},
new Online_video_for_programmers
{
video_name="Yoga for programmers",
season=3,
seasontype=2,
year=2012
}
};
//Last years videos sold
List<Online_video_for_programmers> last_year_videos = new List<Online_video_for_programmers>()
{
new Online_video_for_programmers
{
video_name="websocket for fortran programmers",
season=2,
seasontype=1,
year=2011,
},
new Online_video_for_programmers
{
video_name="cross site scripting for facebook addicts",
season=3,
seasontype=1,
year=2011,
},
new Online_video_for_programmers
{
video_name="Artificial intelligence for self aware robots",
season=2011,
seasontype=3,
year=2011,
}
,
new Online_video_for_programmers
{
video_name="Yoga for programmers",
season=4,
seasontype=2,
year=2011,
},
new Online_video_for_programmers
{
video_name="Yoga for programmers",
season=2,
seasontype=2,
year=2011
}
};
}
// Define other methods and classes here
public class Online_video_for_programmers
{
public int seasontype {get;set;} //this can be the id of a year, a quater or month Tyepes are 1: months, 2, for quarters, 3 for year
public int season {get;set;} // when season type is 1, season =1 means january.
//When season type is 2, season=3 means 3rd quater. When seasontype is 3, season =2011 or 2010 etc...
public string video_name {get;set;} //The nambe of the video
public int year {get;set;} // The year the video was published
}
我想使用 current_year_videos 和 last_year_videos 来检索去年而不是今年发布的标题。为此,我使用以下代码:
var result=current_year_videos.Concat(last_year_videos).GroupBy( g=> new { seasontype,season,video_name }).Select(s=> new Online_video_for_programmers{ seasontype=s.Key.seasontype, season=s.Key.season, video_name=s.Key.video_name });
上面的代码给了我今年和去年都生产的代码,这样我就可以很容易地找到丢失的代码。
这就是问题所在。2011年全年制作的视频“人工智能的自我意识机器人”,而2012年有3个月的制作。我不希望看到它在2012年丢失。只有在没有制作的情况下才应该丢失。一切都在 2012 年。问题是,如何调整我的查询以在结果中包含此条件。到目前为止,我花了一些时间想出不同的东西,但没有成功。
希望有人可以提供帮助。
提前谢谢了