Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get,set and value keyword in c#.net

Tags:

c#

.net

What is value keyword here and how is it assigning the value to _num? I'm pretty confused, please give the description for the following code.

    private int _num;
    public int num
    { 
        get 
        {
            return _num;
        }
        set 
        {
            _num=value;
        }
    }

    public void button1_click(object sender,EventArgs e)
    {
        num = numericupdown.Value;
    }
like image 723
rtz87 Avatar asked Aug 18 '12 14:08

rtz87


Video Answer


1 Answers

In the context of a property setter, the value keyword represents the value being assigned to the property. It's actually an implicit parameter of the set accessor, as if it was declared like this:

private int _num
public int num
{ 
    get 
    {
        return _num;
    }
    set(int value)
    {
        _num=value;
    }
}

Property accessors are actually methods equivalent to those:

public int get_num()
{
    return _num;
}

public void set_num(int value)
{
    _num = value;
}
like image 138
Thomas Levesque Avatar answered Sep 20 '22 05:09

Thomas Levesque