Ref
??? 传引用???
Out(a new feature of C# 7)
string input1 = Console.ReadLine();
if (int.TryParse(input1,out int result1))
{
Console.WriteLine($"result:{result1}");
}
else
{
Console.WriteLine("Not a number.");
}
注:
(1)Console.ReadLine() 获得用户输入
(2)TryParse is declared to return a bool type whether the parsing is successful or not.
(3)public static bool TryParse(string s, out int result);
Invoking this method, the result variable doesn’t need to be initialized beforehand; the variable is initialized within the method.
In
The in modifier guarantees the data that is sent into the method does not change (when passing a value type).
网友评论