Adding Other Elements

Let's add other comic books.

  1. Create an array variable called _comicBooks that being a list of comic books.

    private static ComicBook[] _comicBooks = new ComicBook[]
    {
    
    };
    
  2. Add some books into the array.

    private static ComicBook[] _comicBooks = new ComicBook[]
    {
        new ComicBook()
        {
            SeriesTitle = "The Amazing Spider-Man",
            IssueNumber = 700,
            DescriptionHtml = "<p>Final issue! Witness the final hours of Doctor Octopus' life and his one, last, great act of revenge! Even if Spider-Man survives...<strong>will Peter Parker?</strong></p>",
            Artists = new Artist[]
            {
                new Artist() { Name = "Dan Slott", Role = "Script" },
                new Artist() { Name = "Humberto Ramos", Role = "Pencils" },
                new Artist() { Name = "Victor Olazaba", Role = "Inks" },
                new Artist() { Name = "Edgar Delgado", Role = "Colors" },
                new Artist() { Name = "Chris Eliopoulos", Role = "Letters" },
            },
            Favorite = false
        },
        new ComicBook()
        {
            SeriesTitle = "The Amazing Spider-Man",
            IssueNumber = 657,
            DescriptionHtml = "<p><strong>FF: THREE TIE-IN.</strong> Spider-Man visits the FF for a very private wake--just for family.</p>",
            Artists = new Artist[]
            {
                new Artist() { Name = "Dan Slott", Role = "Script" },
                new Artist() { Name = "Marcos Martin", Role = "Pencils" },
                new Artist() { Name = "Marcos Martin", Role = "Inks" },
                new Artist() { Name = "Muntsa Vicente", Role = "Colors" },
                new Artist() { Name = "Joe Caramagna", Role = "Letters" }
            },
            Favorite = false
        },
        new ComicBook()
        {
            SeriesTitle = "Bone",
            IssueNumber = 50,
            DescriptionHtml = "<p><strong>The Dungeon & The Parapet, Part 1.</strong> Thorn is discovered by Lord Tarsil and the corrupted Stickeaters and thrown into a dungeon with Fone Bone. As she sleeps, a message comes to her about the mysterious \"Crown of Horns\".</p>",
            Artists = new Artist[]
            {
                new Artist() { Name = "Jeff Smith", Role = "Script" },
                new Artist() { Name = "Jeff Smith", Role = "Pencils" },
                new Artist() { Name = "Jeff Smith", Role = "Inks" },
                new Artist() { Name = "Jeff Smith", Role = "Letters" }
            },
            Favorite = false
        }
    };
    
  3. Change the GetComicBook function to process by given an input parameter.

    public ComicBook GetComicBook( int id )
    {
        ComicBook comicBookReturned = null;
    
        foreach (var comicBook in _comicBooks)
        {
            if (comicBook.Id == id)
            {
                comicBookReturned = comicBook;
                break;
            }
        }
    
        return comicBookReturned;
    }
    

results matching ""

    No results matching ""