How to Use out Reserved Words in C # (cs)

Source: Internet
Author: User
Tags sendmsg

Return the value of this variable. The simplest application is division. For example, you need a division method to obtain the remainder and quotient at the same time. However, a normal method can only obtain one return value, in this case, you can use the Out parameter to return another value.

When you want the method to return multiple values, it is very useful to declare the out method.
You can still return a value using the out parameter. A method can have more than one out parameter.
To use the out parameter, you must use the parameter as the out parameter to pass it to the method explicitly. The value of the out parameter is not passed to the out parameter.
You do not need to initialize the variable passed as the out parameter. However, the out parameter must be assigned a value before the method is returned.
The property is not a variable and cannot be passed as an out parameter.

Example

// Obtain the returned value
Private string sendMsg (string SendMessageResult, out int FailCount, out int SessCount, out int AllCount, out string sRe)
{
String sStr = "";
String Result = "";
Int dtCount = dtTemp. Rows. Count;
Int dtFailCount = dtCount;
Int dtSessCount = 0;
SStr = SendMessageResult. Substring (0, 1 );
If (sStr = "0 ")
{
DtFailCount = Convert. ToInt32 (SendMessageResult. Substring (2 ));
DtSessCount = dtCount-dtFailCount;
Result = "The message is sent successfully." + dtSessCount. ToString () + ", failed" + dtFailCount. ToString () + "message ";
}
FailCount = dtFailCount;
SessCount = dtSessCount;
AllCount = dtCount;
SRe = sStr;
Return Result;
}

// Call

Private void btnSend_Click (object sender, EventArgs e)

{

 
Int FailCount;
Int SessCount;
Int AllCount;
String sRe;
String sSendMsg = sendMsg (e. Result, out FailCount, out SessCount, out AllCount, out sRe );

}


From SYZ_YUMEIZHOU_YY

Related Article

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.