zoukankan      html  css  js  c++  java
  • .net out ref

    public void ChangeStringBuilder1(StringBuilder str)
    {
    str.Append("yes");
    }

    public void ChangeStringBuilder2(ref StringBuilder str)
    {
    str.Append("yes");
    }

    public void ChangeStringStr1(string str)
    {
    str += "yes";
    }

    public void ChangeStringStr1(ref string str)
    {
    str += "yes";
    }

    public void ChangeStringStr2(out string str)
    {
    string strTemp = "ok";
    str = strTemp + "yes";
    }

    static void Main(string[] args)
    {
    StringBuilder strBuilder1 = new StringBuilder("str1");
    StringBuilder strBuilder2 = new StringBuilder("str2");
    new Program().ChangeStringBuilder1(strBuilder1);
    new Program().ChangeStringBuilder1(strBuilder2);
    Console.WriteLine(strBuilder1.ToString());
    Console.WriteLine(strBuilder2.ToString());

    string str1 = "str1";
    string str2 = "str2";
    string str3 = "str3";
    new Program().ChangeStringStr1(str1);
    new Program().ChangeStringStr1(ref str3);
    new Program().ChangeStringStr2(out str2);
    Console.WriteLine(str1.ToString());
    Console.WriteLine(str2.ToString());
    Console.WriteLine(str3.ToString());

    }

    结果:

    str1yes
    str2yes
    str1
    okyes
    str3yes
    Press any key to continue . . .

    寻找21世纪的伯牙
  • 相关阅读:
    第四阶段学习总结
    第三阶段学习总结
    第二阶段学习总结
    第一阶段内容的学习总结
    第四单元及OO课程总结
    关于工具的碎碎念
    第三单元博客总结
    第二单元博客总结
    第一单元作业总结
    实验五 单元测试
  • 原文地址:https://www.cnblogs.com/2814/p/2848927.html
Copyright © 2011-2022 走看看