c#之带有out输出参数的方法定义及使用示例

namespace testhasharrayds
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //a,b,c为testout的初始预备工作
            string a = "盖";
            string b = "房";
            string c=string.Empty;
            //在调用时,要特意为输出参数c加上out,不然报错哟
            testout(a,b,out c);
            //运行完testout方法后,可以在其它地方调用输出参数c的值
            label4.Text = c;
            
        }
        //声明一个带有输出OUT参数的方法,注意语法 out 数据类型 方法参数
        void testout(string x, string y, out string z)
        {
            z = x + y;
        }
    }
}
请使用浏览器的分享功能分享到微信等