473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Q: is there a C# equ. of the Delphis With x do?

Hi!

I often come across situations where i have a major code string for
accessing objects, variables and so on

In delphi, you could enter:

With mainObj.ThisControl.ThisProperty do
begin
x := dsdsa;
end;

instead of mainObj.ThisControl.ThisProperty.x := dsdsa;

It it possbile to do this in c#?

Regards

Martin Arvidsson
Nov 17 '05 #1
4 1312
Unfortunately, there is no such thing in C#.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:OA**************@TK2MSFTNGP14.phx.gbl...
Hi!

I often come across situations where i have a major code string for
accessing objects, variables and so on

In delphi, you could enter:

With mainObj.ThisControl.ThisProperty do
begin
x := dsdsa;
end;

instead of mainObj.ThisControl.ThisProperty.x := dsdsa;

It it possbile to do this in c#?

Regards

Martin Arvidsson

Nov 17 '05 #2
The C# way is to use the following:

ThisPropertyType temp = mainObj.ThisControl.ThisProperty;

temp.x = whatever;
temp.y = something;
..
..
..

The with statement has been discussed many times before and has always
been declared as evil, because it can lead to hard to debug problems
with overlapping names

HTH,
Stefan

Visual Systems AB (Martin Arvidsson) wrote:
Hi!

I often come across situations where i have a major code string for
accessing objects, variables and so on

In delphi, you could enter:

With mainObj.ThisControl.ThisProperty do
begin
x := dsdsa;
end;

instead of mainObj.ThisControl.ThisProperty.x := dsdsa;

It it possbile to do this in c#?

Regards

Martin Arvidsson

Nov 17 '05 #3
Note that the alternative suggested by Stefan has the additional benefit of
allowing you do use more than one shortcut at the same time. The 'With'
block (in VB or Delphi) allows only one shortcut at a time via 'With'. In
addition, one of the major drawbacks of 'With' is that intellisense does not
help you identify the object within the block - you have to examine the
header (ok if you have a short block, but otherwise not so good).

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter

"Stefan Simek" wrote:
The C# way is to use the following:

ThisPropertyType temp = mainObj.ThisControl.ThisProperty;

temp.x = whatever;
temp.y = something;
..
..
..

The with statement has been discussed many times before and has always
been declared as evil, because it can lead to hard to debug problems
with overlapping names

HTH,
Stefan

Visual Systems AB (Martin Arvidsson) wrote:
Hi!

I often come across situations where i have a major code string for
accessing objects, variables and so on

In delphi, you could enter:

With mainObj.ThisControl.ThisProperty do
begin
x := dsdsa;
end;

instead of mainObj.ThisControl.ThisProperty.x := dsdsa;

It it possbile to do this in c#?

Regards

Martin Arvidsson

Nov 17 '05 #4
Fortunately, there is no such thing in C#

--
Grace + Peace,
Peter N Roth
Engineering Objects International
http://engineeringobjects.com
Home of Matrix.NET
"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:OA**************@TK2MSFTNGP14.phx.gbl...
Hi!

I often come across situations where i have a major code string for
accessing objects, variables and so on

In delphi, you could enter:

With mainObj.ThisControl.ThisProperty do
begin
x := dsdsa;
end;

instead of mainObj.ThisControl.ThisProperty.x := dsdsa;

It it possbile to do this in c#?

Regards

Martin Arvidsson

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
42
by: Irmen de Jong | last post by:
Pickle and marshal are not safe. They can do harmful things if fed maliciously constructed data. That is a pity, because marshal is fast. I need a fast and safe (secure) marshaler. Is xdrlib the...
6
by: Nick Dreyer | last post by:
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds. Can anyone tell me if that is possible, or...
7
by: Office Drone | last post by:
I'm a bit confused about memory usage, and for some reason I wasn't able to find a single point-of-call to get the amount of memory available. If we take, for instance, the Windows platform: ...
39
by: Antoon Pardon | last post by:
I was wondering how people would feel if the cmp function and the __cmp__ method would be a bit more generalised. The problem now is that the cmp protocol has no way to indicate two objects are...
6
by: Henro V | last post by:
And if there is one, is there a way to make forms that are wider? For every day on the form (first field) it needs to be followed by 52(!) datefields. I've widened the form as far as I can but I...
10
by: Willem | last post by:
Looking for some opinions on alternatives to programming with Access. I find that quite often I need to loop through my recordsets (first to last) performing calculations and was wondering if...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
5
by: B1ackwater | last post by:
We've fooled around with Access a bit, but only using the single-user store-bought version. It seems to be a good database - versatile and infinitely programmable - and can apparently be used as a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.