Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

variable and function with same name

Name: Anonymous 2010-09-18 22:50

Suppose I have a private boolean variable named isCool.

What should the setter and getter functions for this variable be called? setIsCool()? getIsCool() is not as nice sounding as simply isCool().

I would make the variable public, but how do I know with absolute certainty that I won't need to do some additional stuff every time before setting or getting, which would want a function to handle that without breaking the interface.

Name: Anonymous 2010-09-19 0:46

Figured this one out: since I'm using C# I can just define properties that set and get member variables. Clean and smart.

as in:
private bool isCool;

public bool IsCool
{
   get
   {
      return isCool;
   }
   set
   {
      isCool = value;
   }
}

Then you can just go MyClass.isCool = true;
or if (MyClass.isCool)

Definitely a nice thing to include in that language for a number of other reasons too.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List