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

using statement with comma

P: n/a
The below seems to work...
using(dbconn=DatabaseHelper.CreateConnection("Davi d_Projects"))
{
using(dbcmd=GetSQLSearchCommand(dbconn))
{
// code here
}
}
However, this version doesn't. Any ideas?
using((dbconn=DatabaseHelper.CreateConnection("Dav id_Projects")),(dbcmd=GetS
QLSearchCommand(dbconn)))
{
// code here
}

Visual Studio .NET underlines the , in red and complains "Invalid expression
term ','".
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Why should this work?

It is the same as

while(statement)
{
while(statement)
{
}
}

compared to

while((statement), (statement))
{
}
On Fri, 11 Mar 2005 10:18:53 -0000, David Parker <dp@kewly.com> wrote:
The below seems to work...
using(dbconn=DatabaseHelper.CreateConnection("Davi d_Projects"))
{
using(dbcmd=GetSQLSearchCommand(dbconn))
{
// code here
}
}
However, this version doesn't. Any ideas?
using((dbconn=DatabaseHelper.CreateConnection("Dav id_Projects")),(dbcmd=GetS
QLSearchCommand(dbconn)))
{
// code here
}

Visual Studio .NET underlines the , in red and complains "Invalid
expression
term ','".


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

P: n/a
In the documentation there is the following example of the using
statement...
using (Font MyFont = new Font("Arial", 10.0f), MyFont2 = new Font("Arial",
10.0f))

I'm guessing the problem is because I'm trying to use two different types
(SqlConnection and SqlCommand) instead of just one (as in the Font example).
Nov 16 '05 #3

P: n/a
Ah, in that case it would be more like

for(int i = 0, j = 1;;)

Only one type declaration is allowed, i and j must be of the same type.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4

P: n/a
From the C# specification:

When a resource-acquisition takes the form of a local-variable-declaration,
it is possible to acquire multiple resources of a given type.
So you are correct; the type of the resources being acquired in the using
statement must be the same.HTHDalePresMCAD, MCDBA, MCSE"David Parker"
<dp@kewly.com> wrote in message news:eR*************@TK2MSFTNGP10.phx.gbl...
In the documentation there is the following example of the using
statement...
using (Font MyFont = new Font("Arial", 10.0f), MyFont2 = new Font("Arial",
10.0f))

I'm guessing the problem is because I'm trying to use two different types
(SqlConnection and SqlCommand) instead of just one (as in the Font
example).

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.