Hello All,
I am a CSharp newbie - moving across from Delphi. For the most part I find things easy - not surprising given the origins of CSharp. However, every once in a while I find myself looking for a Delphi equivalent in CSharp. Right now I am wondering if there is a CSharp equivalent for the Delphi WITH keyword. e.g.
with Object do
begin
end;
Does something similar exist in CSharp? I'd much appreciate the tip.
mihir soniPosted Jul 17, 2010, 9:28 AM
Fred AtPosted Jul 17, 2010, 9:13 AM
What WITH does in Delphi is provides a shortcut way of referencing the Object in the With Object do bit. The advantage is that a clutch of
Object.PropertyA:=x;
Object.MethodA(Param1,Param2...)
y:=Object.PropertyB;
can be replaced with
with Object do
begin
PropertyA:=x;
MethodA(Param1,Param2...);
y:=PropertyB;
end;
This makes for more compact code that is also less liable to error.
mihir soniPosted Jul 17, 2010, 3:00 AM