The difference between c#ref and out

Source: Internet
Author: User

ref: You need to assign a value before calling to pass a reference to a parameter, not a value. (there are in and out)

out: The method is assigned a value , and the value is passed to the method from within the method. (only out of the input)

Both of them belong to reference passing;

1         #regionThe difference between ref and out2         /*3 Ref: You need to assign a value before calling to pass a reference to a parameter, not a value. (There are in and out)4 5 Out : The method is assigned a value, and the value is passed to the method from within the method. (only out of the input)6 7 both of them belong to reference passing;8         */9             stringUID ="Admin";Ten             stringPWD ="111111"; //The correct login password is "666666", here is the wrong password  One             stringmsg = null; A             if(Checklogin (UID, PWD, outmsg)) -             { -Console.WriteLine ("Login Successful"); the             } -             Else -             { -Console.WriteLine ("logon Failure, error reason is"+msg); +             } -              +             #endregion
1          Public Static BOOLChecklogin (stringUidstringPwd out stringmsg)2         {3             if(UID = ="Admin"&& pwd = ="666666") //account password is correct, msg is empty, login successful 4             {5msg =NULL;6                 return true;7             }8             Else9             {Tenmsg ="incorrect user name or password"; One                 return false; A             } -}

Convert out to ref results.

The difference between c#ref and out

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.