Ok I do certainly understand what you are saying.. so adding a variable is
in that one point additional memory space?.. and second point again doing
Table.Columns three times, that gets to have "table" ( your local variable)
evaluated 3 times.. so isn't With the better way than a local variable
Unless I missed the bigger picture here !
VJ
>> Is there any performance advantage if I follow example 2.
>> Which one is preferred.
[quoted text clipped - 27 lines]
>
> Personally that's what I'd do - I'm not a fan of "With".
> Ok I do certainly understand what you are saying.. so adding a variable is
> in that one point additional memory space?..
No, as they compile to the same code.
> and second point again doing Table.Columns three times, that gets to
> have "table" ( your local variable) evaluated 3 times..
Evaluating a local variable is very quick. Evaluating a property may
not be. That's the difference.
> so isn't With the better way than a local variable
>
> Unless I missed the bigger picture here !
Well, the bigger picture starts with the fact that With/End With gets
compiled to the same code as using a local variable. How else would you
expect the IL to look?
Compile the following code, and compare the compiled methods in ILDASM:
Public Class Foo
Dim x As String = "Hello"
Public Shared Sub Main
Dim y as new Foo
With y.x
Console.WriteLine (.Length)
Console.WriteLine (.Substring(1))
End With
End Sub
Public Shared Sub Main2
Dim y as new Foo
Dim s as String = y.x
Console.WriteLine (s.Length)
Console.WriteLine (s.Substring(1))
End Sub
End Class

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
VJ - 22 Mar 2007 02:41 GMT
Yes after I posted here that is what I did (write and check the ILDASM) and
got it. Thanks a lot for explaination Jon..
VJ
>> Ok I do certainly understand what you are saying.. so adding a variable
>> is
[quoted text clipped - 38 lines]
>
> End Class
Tim - 22 Mar 2007 18:53 GMT
Thanks VJ and Jon.
> Yes after I posted here that is what I did (write and check the ILDASM)
> and got it. Thanks a lot for explaination Jon..
[quoted text clipped - 43 lines]
>>
>> End Class