Actually there is no performance penalty using property vs using public
field

Enclosed is my example of il code produced first using property, and next
using public variable.

Regards
Daniel

// using property

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01
00 00 00 )
  // Code size       30 (0x1e)
  .maxstack  2
  .locals init ([0] class ConsoleApplication10.Class1 c)
  IL_0000:  newobj     instance void ConsoleApplication10.Class1::.ctor()
  IL_0005:  stloc.0
  IL_0006:  ldloc.0
  IL_0007:  ldstr      "hello world"
  IL_000c:  stfld      string ConsoleApplication10.Class1::test
  IL_0011:  ldloc.0
  IL_0012:  callvirt   instance void ConsoleApplication10.Class1::WriteIt()
  IL_0017:  call       string [mscorlib]System.Console::ReadLine()
  IL_001c:  pop
  IL_001d:  ret
} // end of method Class1::Main


// Using public fields
.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint
  .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01
00 00 00 )
  // Code size       30 (0x1e)
  .maxstack  2
  .locals init (class ConsoleApplication10.Class1 V_0)
  IL_0000:  newobj     instance void ConsoleApplication10.Class1::.ctor()
  IL_0005:  stloc.0
  IL_0006:  ldloc.0
  IL_0007:  ldstr      "hello world"
  IL_000c:  stfld      string ConsoleApplication10.Class1::test
  IL_0011:  ldloc.0
  IL_0012:  callvirt   instance void ConsoleApplication10.Class1::WriteIt()
  IL_0017:  call       string [mscorlib]System.Console::ReadLine()
  IL_001c:  pop
  IL_001d:  ret
} // end of method Class1::Main

-----Original Message-----
From: Urs Eichmann [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 22 October 2003 3:34 a.m.
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Do properties need a 'holder' keyword?

> Also, some ams have rules. Our rules say: NO PUBLIC VARIABLES. NEVER.

Thomas,
IMHO This is a good rule - as long as it applies to public classes only. But
if the classes are private to your assembly, I don't see the point of not
having public members. After all, there can be quite a performance penalty
if you use properties  vs. Member variables.

Urs

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

________________________________________

Caution:  The content of this email is confidential and may be legally
privileged.  If it is not intended for you, please email the sender
immediately and destroy the original message.  You may not copy, disclose or
use the contents of this message in any way.

Important: Employees of EziBuy Ltd are expressly required not to make any
offensive or defamatory statements and/or not to communicate offensive
material. Any such communication is contrary to company policy and outside
the scope of the employment of the individual concerned. EziBuy Ltd will
therefore not accept any liability in respect of such a communication, and
the employee responsible will be personally liable for any damages or other
liability arising.
________________________________________


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to