what is the Value in Cycle struct

B

bobby2555

Hello,
I am reading the book for the MCTS 536 and I came across this code which is
struct Cycle and in 13 line there is something (public int Value) that I do
not understand what it is.
Is it a method or a variable?

Here is the code

struct Cycle
{
// Private fields
int _val, _min, _max;

// Constructor
public Cycle(int min, int max)
{
_val = min;
_min = min;
_max = max;
}

public int Value
{
get { return _val; }
set
{
if (value > _max)
_val = _min;
else
{
if (value < _min)
_val = _max;
else
_val = value;
}
}
}

public override string ToString()
{
return Value.ToString();
}

public int ToInteger()
{
return Value;
}

// Operators (new in .NET 2.0)
public static Cycle operator +(Cycle arg1, int arg2)
{
arg1.Value += arg2;
return arg1;
}

public static Cycle operator -(Cycle arg1, int arg2)
{
arg1.Value -= arg2;
return arg1;
}
}
 
M

Martin Honnen

bobby2555 said:
I am reading the book for the MCTS 536 and I came across this code which is
struct Cycle and in 13 line there is something (public int Value) that I do
not understand what it is.
Is it a method or a variable?
public int Value
{
get { return _val; }
set
{
if (value > _max)
_val = _min;
else
{
if (value < _min)
_val = _max;
else
_val = value;
}
}
}

That is a property:
http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx
 
P

Peter Duniho

bobby2555 said:
Hello,
I am reading the book for the MCTS 536 and I came across this code which is
struct Cycle and in 13 line there is something (public int Value) that I do
not understand what it is.
Is it a method or a variable?

Neither. It's a property.

I don't know what "MCTS 536" is, but if it's some kind of certification
involving your knowledge of C# and you don't recognize a property in C#
when you see one, you are getting WAY ahead of yourself.

Pete
 

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