Click to See Complete Forum and Search --> : [RESOLVED] help (very simple)
Crash893
Sep 25th, 2006, 03:38 PM
i know i know i should know this
but how can you do a "with"
example in vb would be
with OFD_open
.something
.somethingelse
end with
i have no idea how to do this in c# and everything i try to seach on doesnt want to search the word "with" becuase its joiner word
mendhak
Sep 25th, 2006, 03:42 PM
Ah, sorry, I misunderstood the question.
There is no 'With' in C#.
Crash893
Sep 25th, 2006, 04:47 PM
well then
im not crazy after all
or not becuase of this anyway
thanks
jmcilhinney
Sep 25th, 2006, 06:01 PM
Let's not forget to resolve our threads.
"With" in VB doesn't really do anything that can't be done very easily without it. There are only two valid reasons to use a "With" statement in VB:
1. You want to get a single reference via a long chain, e.g.myDataAdapter.SelectCommand.Parameters.AddWithValue("@Paramater1", myTextBox1.Text)
myDataAdapter.SelectCommand.Parameters.AddWithValue("@Paramater2", myTextBox2.Text)becomes:With myDataAdapter.SelectCommand.Parameters
.AddWithValue("@Paramater1", myTextBox1.Text)
.AddWithValue("@Paramater2", myTextBox2.Text)
End Withso that myDataAdapter.SelectCommand.Parameters gets evaluated only once. This can be mimicked using a local variable with only slightly more code.
2. You want to access multiple members of the same variable without typing the variable name multiple times. This is mostly negated by the fact that C# Intellisense kicks in as soon as you start typing, although you can prompt VB Intellisense with Ctrl+Space anyway.
The "With" statement is intended to make code easier to read but many people misuse it and it actually has the opposite affect. Any dots not at the beginning of a line are actually harder to see, so to use a With block like this:With myTextBox
.Text = "Hello World"
MessageBox.Show(.Text)
End Withwould be considered bad coding style.
Crash893
Sep 25th, 2006, 08:15 PM
yea i just didnt want to type it in over and over.
i just put it on the clipboard and did it that way
jmcilhinney
Sep 25th, 2006, 08:39 PM
So... this thread is resolved, correct?
mendhak
Sep 26th, 2006, 04:13 PM
Correct. ;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.