美文网首页
Ref、Out、In

Ref、Out、In

作者: 津涵 | 来源:发表于2019-02-02 13:41 被阅读0次

    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).

    相关文章

      网友评论

          本文标题:Ref、Out、In

          本文链接:https://www.haomeiwen.com/subject/kyessqtx.html