Out parm syntax error

  • Thread starter Thread starter Andrew Connell
  • Start date Start date
A

Andrew Connell

I have a method which returns a value via an out parm. Here's the prototype of the function:
public DbActionResult Insert(out int securityGroupID, string title, string description)

Now, when I try to pull the value out of that list, no matter the syntax, I can't get it to work... keep getting an error of "can't convert out int to int" or vice versa.

Data.SecurityGroup sg = new Data.SecurityGroup();
result = sg.Insert(out securityGroup.GroupID,
securityGroup.Title,
securityGroup.Description);
_securityGroup = securityGroup;

Any ideas what's throwing my error? It looks like everything I'm doing is correct. I also tried using a temp variable (int goupID = 0) in place of the securityGroup.GroupID property and then assigning that temp to the object property, but I got the same error.
 
Andrew,

The property will never work, as you can not assign a property to a
"ref" parameter or to an "out" parameter. The idea is that on return, the
assignment can not be made (an assignment for a property is like another
method call, it is not like the assignment of a field).

This is going to sound like a foolish question, but when you assign the
value to the temp variable, do you use "out" on that variable as well when
passing to the method?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a method which returns a value via an out parm. Here's the prototype
of the function:
public DbActionResult Insert(out int securityGroupID, string title, string
description)

Now, when I try to pull the value out of that list, no matter the syntax, I
can't get it to work... keep getting an error of "can't convert out int to
int" or vice versa.

Data.SecurityGroup sg = new Data.SecurityGroup();
result = sg.Insert(out securityGroup.GroupID,
securityGroup.Title,
securityGroup.Description);
_securityGroup = securityGroup;

Any ideas what's throwing my error? It looks like everything I'm doing is
correct. I also tried using a temp variable (int goupID = 0) in place of
the securityGroup.GroupID property and then assigning that temp to the
object property, but I got the same error.
 
Makes sense RE the property (looks like I have a lot of things to go back
and fix).

In response to your question: Do you mean doing something like this?

Data.SecurityGroup sg = new Data.SecurityGroup();
int groupID = 0;
result = sg.Insert(out groupID,
securityGroup.Title,
securityGroup.Description);
securityGroup.GroupID = groupID;
_securityGroup = securityGroup;

I'm fairly certain I did try that.
 
Andrew,

Can you give the compiler error that you are getting for this? The
syntax that you are using looks like it should work (with the local
variable).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andrew Connell said:
Makes sense RE the property (looks like I have a lot of things to go back
and fix).

In response to your question: Do you mean doing something like this?

Data.SecurityGroup sg = new Data.SecurityGroup();
int groupID = 0;
result = sg.Insert(out groupID,
securityGroup.Title,
securityGroup.Description);
securityGroup.GroupID = groupID;
_securityGroup = securityGroup;

I'm fairly certain I did try that.

message news:[email protected]...
Andrew,

The property will never work, as you can not assign a property to a
"ref" parameter or to an "out" parameter. The idea is that on return, the
assignment can not be made (an assignment for a property is like another
method call, it is not like the assignment of a field).

This is going to sound like a foolish question, but when you assign the
value to the temp variable, do you use "out" on that variable as well when
passing to the method?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a method which returns a value via an out parm. Here's the prototype
of the function:
public DbActionResult Insert(out int securityGroupID, string title, string
description)

Now, when I try to pull the value out of that list, no matter the
syntax,
 
Back
Top