Necesito ayuda con este problema de Get y Set | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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