views:

82

answers:

4

Given the code below, what does the "with" keyword do? I'm not very familiar with it, and I'm not sure of its purpose.

Sub NotePage_Load()


With Request.Form

Thanks Kevin

A: 

With is the equivalent of adding Request.Form before any references in the with block.

With Request.Form
    Dim count as int = .Count
End With

versus:

Dim count as int = Request.Form.Count
Gavin Miller
A: 

With allows you to omit the part after the with and just use the dot operator - . to access properties, members and methods.

Daniel A. White
A: 

Well it acts as an alias to Request.Form

So you don't need to do

Request.Form.this

or

Request.Form.this

you can just do

this

or

that
John Nolan
+4  A: 

It's a shorthand... everything within the With..End With block will be treated as if something is appended in front of it.

Ex:

With Request.Form
  ["xxx"] = "yyy"
  ["aaa"] = "bbb"
End With

is equal to the following:

Request.Form["xxx"] = "yyy"
Request.Form["aaa"] = "bbb"
Adrian Godong
Thanks everyone. Very helpful. Makes sense, simple concept!
Kevin