Не работает код. Выдает ошибку, что "ожидался класс, делегат, перечисление, интерфейс или структура" (CS1518) - C#

Узнай цену своей работы

Формулировка задачи:

Задача была такая: Создать коллекцию комиксов и с помощью LINQ сформировать запрос на поиск самых дорогих комиксов, стоимостью от 500 долларов. Помогите, пожалуйста, довести до ума. Вот, что вышло:
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. class Comic
  4. {
  5. public string Name { get; set; }
  6. public int Issue { get; set; }
  7. }
  8. private static IEnumerable <Comic> BuildCatalog()
  9. {
  10. return new List<Comic> {
  11. new Comic { Name = "Johnny America vs. the Pinko", Issue = 6 },
  12. new Comic { Name = "Rock and Roll (ограниченный выпуск)", Issue = 19 },
  13. new Comic { Name = "Woman’s Work", Issue = 36 },
  14. new Comic { Name = "Hippie Madness (с опечатками)", Issue = 57 },
  15. new Comic { Name = "Revenge of the New Wave Freak (поврежден)", Issue = 68 },
  16. new Comic { Name = "Black Monday", Issue = 74 },
  17. new Comic { Name = "Tribal Tattoo Madness", Issue = 83 },
  18. new Comic { Name = "The Death of an Object", Issue = 97 },
  19. };
  20. }
  21. private static Dictionary<int, decimal> GetPrices()
  22. {
  23. return new Dictionary<int, decimal> {
  24. { 6, 3600M },
  25. { 19, 500M },
  26. { 36, 650M },
  27. { 57, 13525M },
  28. { 68, 250M },
  29. { 74, 75M },
  30. { 83, 25.75M },
  31. { 97, 35.25M },
  32. };
  33. }
  34. IEnumerable<Comic> comics = BuildCatalog();
  35. Dictionary<int, decimal> values = GetPrices();
  36. var mostExpensive =
  37. from comic in comics
  38. where values[comic.Issue] > 500
  39. orderby values[comic.Issue] descending
  40. select comic;
  41. foreach (Comic comic in mostExpensive)
  42. Console.WriteLine("{0} стоит {1:c}",
  43. comic.Name, values[comic.Issue]);

Решение задачи: «Не работает код. Выдает ошибку, что "ожидался класс, делегат, перечисление, интерфейс или структура" (CS1518)»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Comic
  6. {
  7.     public string Name { get; set; }
  8.     public int Issue { get; set; }
  9.  
  10.  
  11.     public static IEnumerable<Comic> BuildCatalog()
  12.     {
  13.         return new List<Comic> {
  14.             new Comic { Name = "Johnny America vs. the Pinko", Issue = 6 },
  15.             new Comic { Name = "Rock and Roll (ограниченный выпуск)", Issue = 19 },
  16.             new Comic { Name = "Woman’s Work", Issue = 36 },
  17.             new Comic { Name = "Hippie Madness (с опечатками)", Issue = 57 },
  18.             new Comic { Name = "Revenge of the New Wave Freak (поврежден)", Issue = 68 },
  19.             new Comic { Name = "Black Monday", Issue = 74 },
  20.             new Comic { Name = "Tribal Tattoo Madness", Issue = 83 },
  21.             new Comic { Name = "The Death of an Object", Issue = 97 }
  22.             };
  23.     }
  24.  
  25.     public static Dictionary<int, decimal> GetPrices()
  26.     {
  27.         return new Dictionary<int, decimal> {
  28.             { 6, 3600M },
  29.             { 19, 500M },
  30.             { 36, 650M },
  31.             { 57, 13525M },
  32.             { 68, 250M },
  33.             { 74, 75M },
  34.             { 83, 25.75M },
  35.             { 97, 35.25M }
  36.             };
  37.     }
  38. }
  39.  
  40. class Program
  41. {
  42.     static void Main(string[] args)
  43.     {
  44.         IEnumerable<Comic> comics = Comic.BuildCatalog();
  45.         Dictionary<int, decimal> values = Comic.GetPrices();
  46.         var mostExpensive =
  47.         from comic in comics
  48.         where values[comic.Issue] > 500
  49.         orderby values[comic.Issue] descending
  50.         select comic;
  51.         foreach (Comic comic in mostExpensive)
  52.             Console.WriteLine("{0} стоит {1:c}",
  53.             comic.Name, values[comic.Issue]);
  54.         Console.ReadLine();
  55.     }
  56. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 4 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы