Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
theNox94777yWhat did you before c# if this is writing you out, that's a common concept in many programming languages
-
@C0D4 I know.. I come from java where you have to create getters and setters manually. Having access to something inside an object of a different class that I can use just = to change makes me uneasy.
-
@g-m-f I come from java where you have to create getters and setters manually. Having access to something inside an object of a different class that I can use just = to change makes me uneasy
-
private string _foo;
public string Foo
{ get { return _foo;}
set { _foo = value;}
} -
um... what
arent those
like
encapsulated fields
what the
i thought they were automatically set to private if i did that
WHAT THE FUCK -
@bkwilliams Seeing as you're not manipulating the values at any point why not just do
public string Foo { get; set; } -
@itsdaniel0 I would but writing code on a phone is painful. Depending on the case I leave off the set so callers have only the == option.
-
xalez19377y<code>
private string _thingy;
public string getThingy()
{
return _thingy;
}
public void setThingy(string value)
{
_thingy = value;
}
</code>
vs.
<code>
public string Thingy { get; set; }
</code>
I think it's well worth risking a mistake with = and == which is usually rare and easy to catch and fix -
This is also where the Yoda statements prove useful (not a fan myself)
if("foo" == Foo) {}
vs
if(Foo == "foo") {}
That way it'll throw an error since you can't assign to a string -
Umm, just use any decent IDE or editor. AFAIK, = doesn't return a Boolean so it should error out.
Related Rants
I'm learning C#, and the whole properties thing with get; and set; is weirding me out... So many unnecessary mistakes could be made by accidentally using = instead of ==...
rant
wot
getters and setters
c#