This is a question that I've had knocking around in my head
for a
while.
Here are two Person classes:
public class Person1
{
private string _firstName = "";
public void SetFirstName(string firstName)
{
this._firstName = firstName;
}
public string GetFirstName()
{
return this._firstName;
}
}
public class Person2
{
private string _firstName = "";
public string FirstName
{
get
{
return this._firstName;
}
set
{
this._firstName = value;
}
}
}
As you can see, the first class contains two methods that
are used to
set and get the first name of the Person object. The second
class
contains a single property FirstName with a getter and
setter.
For the moment let's put aside all questions of getters and
setters
being evil (I do agree with Holub that there should be a
justifiable
reason for exposing a property for reading or writing.
Let's assume
that there is a valid reason for exposing this property).
My question has to do with the performance of these two
classes and how
the two convert into IL. What's the difference? Is there
a
performance difference? Is there a difference in the
Intermediate
Language? Is there a perceived benefit to using a property
here rather
than two methods?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C# Developers" group.
To post to this group, send email to CSDevelopers googlegroups.com
To unsubscribe from this group, send email to
CSDevelopers-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/CSDevelopers
-~----------~----~----~----~------~----~------~--~---
|