Properties



private string name;
public string Name
{
get { return name; }
set { name = value; }
}

In the above, why doesn't C# just allow one to create a single directive to
make a property?

why not something like

public string Name
{
get { return name; }
set { name = value; }
}

Why the need to declare the same thing basically twice? If, say there was no
block associated with the variable then its assumed to be a field instead of
a property.

i.e.

public string Name; works and is a "Field".

while

public string Name
{
get { return name; }
set { name = value; }
}

is a property.

Thanks,
Jon








.



Relevant Pages

  • Re: XML generation from a Schema
    ... public partial class RefillRequest { ... private string prescriberOrderNumberField; ... public string PrescriberOrderNumber { ... private MandatoryNameType pharmacistAgentField; ...
    (microsoft.public.dotnet.xml)
  • Re: Properties
    ... | Why the need to declare the same thing basically twice? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: XML Generation and consumption
    ... I'm not even sure I'm starting in the right place with HeaderType - ... private string versionField; ... public string version { ... private UsernameTokenType usernameTokenField; ...
    (microsoft.public.dotnet.xml)
  • Re: design pattern of "Business Layer"
    ... private string _oneWorldID; ... private string _respDivName; ... RespDivName = ActiveInd = string.Empty; ... public string OneWorldID ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Properties
    ... | Why the need to declare the same thing basically twice? ...
    (microsoft.public.dotnet.languages.csharp)

Loading