By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,206 Members | 1,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,206 IT Pros & Developers. It's quick & easy.

Equivalent of VB's "with"

P: n/a
Is there an equivalent of VB's "with" statement in c# ?
Jul 5 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
cp

Mr Flibble wrote:
Is there an equivalent of VB's "with" statement in c# ?
Nope.

cp

Jul 5 '06 #2

P: n/a
Mr Flibble wrote:
Is there an equivalent of VB's "with" statement in c# ?
No.

See http://www.pobox.com/~skeet/csharp/faq/#vb.with

Jon

Jul 5 '06 #3

P: n/a
"Mr Flibble" <mr********@flibbyly.wobbly.n.etwrote in message
news:e8**********@custnews.inweb.co.uk...
Is there an equivalent of VB's "with" statement in c# ?
This a FAQ, and the usual reply is "No, thank God!"

:-)
Jul 5 '06 #4

P: n/a
Mr Flibble wrote:
Is there an equivalent of VB's "with" statement in c# ?
Absolutely not.

--
Hope this helps,
Tom Spink
Jul 5 '06 #5

P: n/a
Ahh, Negatory. Boris, you got plan?

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mr Flibble" wrote:
Is there an equivalent of VB's "with" statement in c# ?
Jul 5 '06 #6

P: n/a
Also see:
http://www.tangiblesoftwaresolutions...0VB%20With.htm
(excuse the product plug at the bottom)

Basically, the gist of it is that "With" is no better than an abbreviated
variable named "x" - it's obscure and also implies somehow that the block
centers around the object being With'ed (when it really just centers around
something you didn't want to re-type).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"Mr Flibble" wrote:
Is there an equivalent of VB's "with" statement in c# ?
Jul 6 '06 #7

P: n/a
* David Anton wrote:
Also see:
http://www.tangiblesoftwaresolutions...0VB%20With.htm
(excuse the product plug at the bottom)

Basically, the gist of it is that "With" is no better than an abbreviated
variable named "x" - it's obscure and also implies somehow that the block
centers around the object being With'ed (when it really just centers around
something you didn't want to re-type).
" Another alternative is to refactor so that the With block is a new
method with the object passed in as a parameter. You can use a reduced
parameter name length (without making it obscure)."

How do you reduce the parameter name length? can you give me an example?

Cheers,

Signore Flibble
Jul 6 '06 #8

P: n/a
It's just a possibility that may or may not be appropriate.

For example, instead of:
somehorriblelongnameyoudontwanttoretype.methodone( )
somehorriblelongnameyoudontwanttoretype.methodtwo( )
somehorriblelongnameyoudontwanttoretype.methodthre e()
somehorriblelongnameyoudontwanttoretype.methodfour ()

You *could* just call a new method:
YourMethod(somehorriblelongnameyoudontwanttoretype )

and then the new method defined as:
Public Sub YourMethod(ByVal activeobject As Whatever)
activeobject.methodone()
activeobject.methodtwo()
activeobject.methodthree()
activeobject.methodfour()
End Sub

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"Mr Flibble" wrote:
* David Anton wrote:
Also see:
http://www.tangiblesoftwaresolutions...0VB%20With.htm
(excuse the product plug at the bottom)

Basically, the gist of it is that "With" is no better than an abbreviated
variable named "x" - it's obscure and also implies somehow that the block
centers around the object being With'ed (when it really just centers around
something you didn't want to re-type).

" Another alternative is to refactor so that the With block is a new
method with the object passed in as a parameter. You can use a reduced
parameter name length (without making it obscure)."

How do you reduce the parameter name length? can you give me an example?

Cheers,

Signore Flibble
Jul 6 '06 #9

P: n/a
"David Anton" <Da********@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
It's just a possibility that may or may not be appropriate.

For example, instead of:
somehorriblelongnameyoudontwanttoretype.methodone( )
somehorriblelongnameyoudontwanttoretype.methodtwo( )
somehorriblelongnameyoudontwanttoretype.methodthre e()
somehorriblelongnameyoudontwanttoretype.methodfour ()

You *could* just call a new method:
YourMethod(somehorriblelongnameyoudontwanttoretype )

and then the new method defined as:
Public Sub YourMethod(ByVal activeobject As Whatever)
activeobject.methodone()
activeobject.methodtwo()
activeobject.methodthree()
activeobject.methodfour()
End Sub
Even better would be to make YourMethod a method of the Whatever class.
Making too many calls into another object is known as "feature envy," and it
often (though not always) indicates that there's a new method waiting to be
extracted.

///ark
Jul 6 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.