I've just started learning C#. A common issue I have is when I am working with an object instance and want to access/assign multiple fields then I have to call the object name each time. I come from a background in Delphi and I was wondering if C# has something similar to with..do
block.
For example. Let's say I had School
Class with fields Name
and Address
In Delphi, I could do the following
mySchool = School.new();
with mySchool do
begin
Name := 'School Name';
Address := 'School Address';
end
The compiler would understand that Name
and Address
are being called on the mySchool
object.
Whereas in C# I have to do the following
mySchool = new School();
mySchool.Name = "School Name";
mySchool.Address = "School Address";
I was just wondering if there is a language construct similar to the Delphi one above that would eliminate the need for me to type out the object name repeatedly.
I know in this example is rather trivial and I should rather use a parameterized constructor but my question is for times when I am doing a multitude of things with the same object and having such a language construct would save me quite a bit of typing.
Also, I'm vaguely aware of namespacing although, my understanding is that you can't use an object/variable as a namespace. Please correct me if I'm wrong.