lundi 5 janvier 2015

Filling in a read-only property with an if statement?

I got a question about a practice test from school.


I need to fill in an application that is already half build (windows forms application)


in this line of code it says the following:



public bool DangerousLoad
{
get
{
// ==> Place here the code that has been asked from assignment 1D:

}
}


What they want me to do is this:


Assignment 1D (8points): The property DangerousLoad is not yet done. The property DangerousLoad must get the value true if the ship contains a dangerous load. A load is dangerous if the load is equal to LPG (some sort of gasoline) or Oil. Fill in the property..


So my question is how to do this? because I tried the following:



public bool DangerousLoad
{
get
{
bool lpg;
bool oil;
// ==> Place here the code that has been asked from assignment 1D:
if (DangerousLoad == lpg)
{
DangerousLoad = true;
}
}
}


The thing that I don't understand is this.. I need to place the code right under the comment but when I do it like this it gives me an error about the fact that it's a "read-only" property..


so ye.. how could I fix this that if the dangerous load contains LPG or OIL the property turns true?


Thanks in advance


Aucun commentaire:

Enregistrer un commentaire