S
Smithers
I understand there is no "right" or "wrong" answer to the question posited
below. But I'd appreciate some feedback on the "best practice"
considerations - if there are any.
So here goes:
Are public readonly properties generally frowned upon? If so, then are there
any generally accepted cases where they are considered as okay?
Please consider the following class and notice it has two properties -
EventMessage1 and EventMessage2.
public class MyFabulousEventArgs : System.EventArgs
{
// Declarations
string eventMessage2 = string.Empty;
public readonly string EventMessage1;
// constructor
public MyFabulousEventArgs(string msg1, string msg2)
{
EventMessage1 = eventMessage;
eventMessage2 = eventMessage2;
}
// Properties
public string EventMessage2
{
get { return eventMessage2; }
}
}
My tendency is to implement properties as EventMessage2 above. But in the
case of a custom EventArgs class, it seems quite reasonable to implement as
a public readonly field.
Your Thoughts (not only on the above scenario, but on the general question
of public readonly fields) ???
Thanks!
below. But I'd appreciate some feedback on the "best practice"
considerations - if there are any.
So here goes:
Are public readonly properties generally frowned upon? If so, then are there
any generally accepted cases where they are considered as okay?
Please consider the following class and notice it has two properties -
EventMessage1 and EventMessage2.
public class MyFabulousEventArgs : System.EventArgs
{
// Declarations
string eventMessage2 = string.Empty;
public readonly string EventMessage1;
// constructor
public MyFabulousEventArgs(string msg1, string msg2)
{
EventMessage1 = eventMessage;
eventMessage2 = eventMessage2;
}
// Properties
public string EventMessage2
{
get { return eventMessage2; }
}
}
My tendency is to implement properties as EventMessage2 above. But in the
case of a custom EventArgs class, it seems quite reasonable to implement as
a public readonly field.
Your Thoughts (not only on the above scenario, but on the general question
of public readonly fields) ???
Thanks!