+ 1
Help please
code doesn't work https://code.sololearn.com/cJT1sZLxNqsE/?ref=app
3 Answers
+ 4
By seeing ur program it looks like u r writing property check.
If u r writing property check than u need to remove () from Check() method and in main u have to say Check = 8 and if want to follow standard practice use same name as field with first letter capital.
+ 3
As Pranshu Sachan said, you shouldn't be writing a property like writing a method.
using System;
namespace Sololearn
{
class Check_Age
{
private int age;
public int Check
{
get
{
return age;
}
set
{
if ( value > 0 ) // check new value > 0
{
age = value;
}
}
}
}
class Program
{
static void Main( string[] args )
{
Check_Age c = new Check_Age();
c.Check = 8; // call property set
Console.WriteLine(c.Check); // call property get
}
}
}
+ 1
Thanks