"David" <da*********@hotmail.com> wrote in
news:OK**************@TK2MSFTNGP10.phx.gbl...
What is the analog of With operator from VB.NET in C#?
I only know With-blocks in VB, where you can treat member variables of an
object as if they were locals. There is no equivalent for this syntax in C#.
I think I've read an interview with the C#-designer (Anders Hejlsberg) where
he explains why: As far as I remember, there are too many special cases
where members of a with-object have the same names as local or member
variables or variables of other with blocks.
Think of something like
Dim i as Int32
Dim o as SomeObject
....
With o do
i = o.SomeProperty
End
If o happens to have a member or property named "i", this code will not
behave as expected!
I think he also claimed that using the object-dot-member syntax everywhere
is more readable, but I guess that's a matter of taste.
Niki