Class method doesn't seem to work

T

tshad

I have a class:
*******************************************
public class DecimalType
{
private decimal first = 0; //original data
private decimal data = 0; //current data
public bool nullFirst = false; //original Data null
public bool nullData = false; //current data null

public DecimalType()
{
}

public DecimalType(decimal initial)
{
first = initial;
data = initial;
}

public bool IsNull()
{
return nullData;
}

public bool IsFirstNull()
{
return nullFirst;
}

public void SetNull()
{
nullData = true;
data = 0;
}

public void SetFirstNull()
{
nullFirst = true;
first = 0;
}

// Properties

public decimal First
{
get { return first; }
set { first = value; }
}

public decimal Data
{
get { return data; }
set { data = value; nullData = false; }
}
} // end Class

********************************************

In another program I call the SetNull() method, but it isn't setting my
flag. If I directly set it, it works fine:

public static void GetValueFromDbObject(object dbObjectValue, ref
DecimalType destination)
....
destination.SetNull();
destination.Data = 2000;
destination.nullData = true;
....

If I comment out the direct change (destination.nullData), nullData is still
false. But above it is setting it to true. If I leave the
destination.nullData = true line in, the flag gets set.

Why doesn't the SetNull() method work?

Thanks,

Tom
 
T

tshad

Yosh said:
Because your Data property is setting it to false.

Hence the reason for not putting multiple statements on one line.

I was looking at this over and over and assumed I was somehow setting it
back to false, but couldn't find it.

I actually want it to work that way, but I had put a test in just to see at
what point of the code I was for different types of tests and had forgotten
that when I set the propert to some value, I obviously want the Null to be
false as it isn't null anymore. The "destination.Data = 2000" was setting
to false, as you said.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top