0

Necesito ayuda con este problema de Get y Set

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int pay = Convert.ToInt32(Console.ReadLine()); Payment pay1 = new Payment(); pay1.PaymentValue = pay; } } class Payment { private int paymentValue; //completa la propiedad public int PaymentValue { get {return paymentValue;} set { if(paymentValue > 50000) Console.WriteLine("Error"); else Console.WriteLine("Accepted"); } } } }

12th Dec 2020, 5:56 AM
Andy Eliu González Pérez
Andy Eliu González Pérez - avatar
2 Respostas
+ 2
In set use "value" instead of "paymentValue". Normally you would set paymentValue there like this: set { paymentValue = value; }
12th Dec 2020, 6:10 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
Thanks now I get "error" and "accepted" when it should
12th Dec 2020, 3:49 PM
Andy Eliu González Pérez
Andy Eliu González Pérez - avatar