A
Anders Borum [.NET/C# MCP]
Hello!
With C# 2.0 coming up, I was wondering what your thoughts are regarding the
introduction of access modifiers on set accessors.
Personally, I like the first example, because of its simplicity. The second
seems rather dangerous and the third one - well, quite verbose.
I'm trying to communicate best practices to fellow developers in-house - and
figured some of you already had experience from past projects / languages
with such features.
Your thoughts?
// 1 - using C# 2.0 access modifer on member
public class CmsObject
{
private Guid cmsObjectID;
public Guid CmsObjectID
{
get { return this.cmsObjectID; }
internal set { this.cmsObjectID = value; }
}
}
vs.
// 2 - using an internal access modifier on member
public class CmsObject
{
internal Guid cmsObjectID;
public Guid CmsObjectID
{
get { return this.cmsObjectID; }
}
}
vs.
// 3 using a method to set member
public class CmsObject
{
private Guid cmsObjectID;
public Guid CmsObjectID
{
get { return this.cmsObjectID; }
}
internal void SetCmsObjectID(Guid cmsObjectID)
{
this.cmsObjectID = cmsObjectID;
}
}
Thanks in advance.
With C# 2.0 coming up, I was wondering what your thoughts are regarding the
introduction of access modifiers on set accessors.
Personally, I like the first example, because of its simplicity. The second
seems rather dangerous and the third one - well, quite verbose.
I'm trying to communicate best practices to fellow developers in-house - and
figured some of you already had experience from past projects / languages
with such features.
Your thoughts?
// 1 - using C# 2.0 access modifer on member
public class CmsObject
{
private Guid cmsObjectID;
public Guid CmsObjectID
{
get { return this.cmsObjectID; }
internal set { this.cmsObjectID = value; }
}
}
vs.
// 2 - using an internal access modifier on member
public class CmsObject
{
internal Guid cmsObjectID;
public Guid CmsObjectID
{
get { return this.cmsObjectID; }
}
}
vs.
// 3 using a method to set member
public class CmsObject
{
private Guid cmsObjectID;
public Guid CmsObjectID
{
get { return this.cmsObjectID; }
}
internal void SetCmsObjectID(Guid cmsObjectID)
{
this.cmsObjectID = cmsObjectID;
}
}
Thanks in advance.