A property or indexer may not be passed as an out or ref parameter

R

rwoo_98

I am trying to pass a reference to a method --SomeMethod. This table
resides in a dataset and I refer to the datatable in the dataset using
an indexer. However when I attempt to do this I get the error message,
"A property or indexer may not be passed as an out or ref parameter?"

Here is the code

SomeMethod(ref ds_User.Tables[1]);


The only way I got it to work is to do the following:

DataTable dt_User;
dt_User = ds_User.Tables[1];
SomeMethod(ref dtUser);

Is there a cleaner method of accomplishing this? I know you VB.Net
allows you to use a property or indexer as a ref when calling a method.
Any idea why C# doesn't?

Thanks in advance.
 
G

Guest

I'm not 100% sure but I think you need to Google for "Delegate C#". I
believe that you need to implement a Delegate to "pass" a method.
 
J

James Curran

J

Jeremy Williams

No, as the error states, you cannot do it the way you want. However, is it
really necessary to use 'ref' for the parameter? If you are trying to modify
data in the data table, then 'ref' is not necessary. What does 'SomeMethod'
do? Are you actually trying to change the table reference stored in the
Tables collection of the DataSet?
 
R

rwoo_98

Thanks Jeremy. You are correct, there was no need to make the
parameter a 'ref'. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top