troubleshooting Question

C#: How to check if LIST<T> item exists and sortting

Avatar of trevor1940
trevor1940 asked on
.NET ProgrammingC#
11 Comments1 Solution225 ViewsLast Modified:
Following on from @ gr8gonzo  comment here on serialize and deserialize XML

This will test if a show exist before adding it

            if(tv.Shows.Exists(show => show.TMBDBid == 77236))
            {
                Console.WriteLine("A Discovery Of Witches Exists");
            }
            else
            {
                tv.Shows.Add(new Show()
                {
                    Name = "A Discovery Of Witches",
                    FolderName = "A Discovery Of Witches",
                    TMBDBid = 77236



                });
            }

How do I test if an episode exists

Tried this but both produced errors so didn't  continue  with  Episode.EpisodeNumber etc
if (tv.Shows.Exists(show => show.TMBDBid == 67133 && show.Season.SeasonNumber))

// AND this
if (tv.Shows.Exists(show => show.TMBDBid == 67133 && show.Season => Season.SeasonNumber))

Again expanding on the example  How do I list the episodes?

         foreach (Show show in tv.Shows)
            {
                // Print out what TV shows are listed

                string ShowName = show.Name;
                string ShowID = show.TMBDBid.ToString();
                Console.WriteLine("ShowName: {0}, TMBDBid: {1} ", ShowName, ShowID);
                foreach (Season season in show.Season)
                {
                    String SeasonNumber = season.SeasonNumber.ToString();
                    Console.WriteLine("SeasonNumber: {0}", SeasonNumber);
                }
                foreach(Episode episode in show.season.)
                {
                    // How do I list the episodes?
                   //                Error	CS1061	'Show' does not contain a definition for 'season' and no extension method 'season' accepting a first argument of type 'Show' could be found
                }
            }

Also when adding a new show or episode can you add it in order of show name then SeasonNumber and finally EpisodeNumber
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros