I’m writing a .Net 3.5 C# script for Sony Vegas Pro. I’ve created this method which returns true if it finds a video event with the same timecode as a given audio event.
This works but I’m wondering if I could get rid of the foreach loops using LINQ. I’m just learning LINQ and I’m finding it quite hard so if you could explain your thought steps in getting to the solution, that’d be great.
private bool videoExistsWithSameStart(TrackEvent currentEvent)
{
//Look through each video track - we don't want audio tracks.
var videoTracks = from t in myVegas.Project.Tracks
where t.IsVideo()
select t;
foreach (Track t in videoTracks)
{
foreach (TrackEvent te in t.Events)
{
if (te.Start == currentEvent.Start)
return true;
}
}
return false;
}
Another alternative: