finxxi
finxxi

Reputation: 28

"Get" keyword in a Class method?

What is the difference between the two method definitions, one with get one without? I understand that properties can have get and set keywords, but what about in normal methods like below?

public bool IsEmpty 
{
    get { return _end == _start; }
}

public bool IsEmpty () 
{
    return _end == _start;
}

Upvotes: 0

Views: 617

Answers (1)

CodeCaster
CodeCaster

Reputation: 151594

Neither are method definitions. The first is a read-only property definition:

public bool IsEmpty
{
    get { return _end == _start; }
}

The second looks the same, but misses the get keyword:

public bool IsEmpty
{
    return _end == _start;
}

So it won't compile. Make it a method definition by adding parentheses:

public bool IsEmpty()

Upvotes: 1

Related Questions