Help understanding "get" and "set"
i used to learn c++, now that get and set is really confusing...
can it be explained in a way i understand...?
can it be explained in a way i understand...?
class Foo {
private:
int bar;
public:
void setBar(int b) {
this.bar = b;
}
int getBar() {
return this.bar;
}
}class Foo
{
private int _bar;
public int GetBar()
{
return _bar;
}
public void SetBar(int bar)
{
_bar = bar;
}
}class Foo
{
private int _bar;
public int GetBar() => _bar;
public void SetBar(int bar) => _bar = bar;
}class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}class Foo
{
public int Bar { get; set; }
}