[Convert VB to C #] rare error: Compilation error: the ref or out parameter must be an lvalue

Source: Internet
Author: User

String strmodelid = This. htmodel [This. cmbmodel. selecteditem. tostring ()]. tostring ();
String strorderid = This. httype [This. cmbordertype. selecteditem. tostring ()]. tostring ();
ADODB. recordset rst = new ADODB. recordsetclass ();
RST = DT. testadodb (strorderid, strmodelid );
This. axctlvoucher1.settemplatedata (ref (object) RST );

Change

String strmodelid = This. htmodel [This. cmbmodel. selecteditem. tostring ()]. tostring ();
String strorderid = This. httype [This. cmbordertype. selecteditem. tostring ()]. tostring ();
ADODB. recordset rst = new ADODB. recordsetclass ();
RST = DT. testadodb (strorderid, strmodelid );
Object TMP = (object) RST;
This. axctlvoucher1.settemplatedata (ref TMP );

You can.

 

Cause:

Here we need to consider the details of type forced conversion. During forced conversion, the compiler will generate a temporary reference and then pass this temporary reference to a reference of the same type as the conversion, this temporary reference is special-it is not a left value (L) and cannot be assigned a value! The method for using the ref parameter generally needs to modify this reference. If the temporary reference is directly passed in, the compiler will complain that the ref or out parameter must be an L. WhileCode2. Assign the temporary reference to a regular reference. Then, the regular reference can be copied.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.