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