fork download
  1. using System;
  2.  
  3. namespace AutoSvoystva
  4. {
  5.  
  6. class Car //автоматические свойства
  7. {
  8. private int speed;
  9. public string PetName { get; set; }
  10. public int speed // Обратите внимание на отсутствие круглых скобок.
  11. {
  12. get { return speed; }
  13. set { if (value > 15)
  14. Console.WriteLine("котики");
  15. else speed = value;
  16. }
  17. }
  18. public string Color { get; set; }
  19. public void DisplayStats()
  20. {
  21. Console.WriteLine("Car Name: {0}", PetName);
  22. Console.WriteLine("Speed: {0}", speed);
  23. Console.WriteLine("Color : {0}", Color);
  24. }
  25. }
  26. class Program
  27. {
  28. static void Main(string[] args)
  29. {
  30. Car c = new Car();
  31. c.PetName = "котик";
  32. c.speed = 104;
  33. c.Color = "red";
  34.  
  35. c.DisplayStats();
  36. }
  37. }
  38. }
  39.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(10,20): error CS0102: The type `AutoSvoystva.Car' already contains a definition for `speed'
prog.cs(8,21): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty