B
bg_ie
Hi,
I'm not happy with the way in which I use accessors and was wondering
if there is a better way of defining them. Take the following example
-
class MyClass
{
// prepended to version names appearing in version combo box
private static string versionPrefix;
// the current version selected by user
public currentVersionName = null;
public MyClass()
{
versionPrefix = GetVersionPrefix();
}
...
// prepended to version names appearing in version combo box
public static string VersionPrefix
{
get
{
return versionPrefix;
}
}
...
}
comboBoxVersion.SelectedIndex =
comboBoxVersion.FindStringExact(MClass.VersionPrefix +
myClass.CurrentVersionName);
The problem is the amount of lines versionPrefix and its accessor
takes up within the class definition. What styles do you guys use?
Also, I don't like how the definition and accessor method is split up
and I feel like I have to repeat my comments. It feels to my that
get{} is a property of versionPrefix (you can get me but not set me),
and therefore belongs with its declaration in the same way that static
does. Perhaps I'd prefer to do something like this before my
constructor, but perhaps its not good practice -
// prepended to version names appearing in version combo box
private static string versionPrefix = "Version Name: ";
public static string VersionPrefix { get { return
versionPrefix; }}
Thanks for your suggestions,
Barry.
I'm not happy with the way in which I use accessors and was wondering
if there is a better way of defining them. Take the following example
-
class MyClass
{
// prepended to version names appearing in version combo box
private static string versionPrefix;
// the current version selected by user
public currentVersionName = null;
public MyClass()
{
versionPrefix = GetVersionPrefix();
}
...
// prepended to version names appearing in version combo box
public static string VersionPrefix
{
get
{
return versionPrefix;
}
}
...
}
comboBoxVersion.SelectedIndex =
comboBoxVersion.FindStringExact(MClass.VersionPrefix +
myClass.CurrentVersionName);
The problem is the amount of lines versionPrefix and its accessor
takes up within the class definition. What styles do you guys use?
Also, I don't like how the definition and accessor method is split up
and I feel like I have to repeat my comments. It feels to my that
get{} is a property of versionPrefix (you can get me but not set me),
and therefore belongs with its declaration in the same way that static
does. Perhaps I'd prefer to do something like this before my
constructor, but perhaps its not good practice -
// prepended to version names appearing in version combo box
private static string versionPrefix = "Version Name: ";
public static string VersionPrefix { get { return
versionPrefix; }}
Thanks for your suggestions,
Barry.