private void button22_Click(object sender, System.EventArgs e)
{
string x = "MM";
int y = 12;
increase(x);
increase(y);
MessageBox.Show(x);
MessageBox.Show(y.ToString());

} private void increase(ref object x)
{
if(x == System.Type.GetType("string"))
x = "QQ";
else
x = 13;
}咋个实现修改x y的值哦?

解决方案 »

  1.   

       private void button1_Click(object sender, EventArgs e)
            {
             string x = "MM";
             object x1 = x;
                int y = 12;
                object y1 = y;
                increase( ref x1);
                increase(ref y1);
                MessageBox.Show(x);
                MessageBox.Show(y.ToString());        }
      

  2.   

    private void button22_Click(object sender, System.EventArgs e)
            {
                object x = "MM";
                object y = 12;
                increase(ref x);
                increase(ref y);
                MessageBox.Show(x);
                MessageBox.Show(y.ToString());        } 
            private static void increase(ref object x)
            {
                if (x.GetType() == Type.GetType("System.String"))
                    x = "QQ";
                else
                    x = 13;
            } 
      

  3.   

    private void button22_Click(object sender, System.EventArgs e) 

    string x = "MM";
                int y = 12;
                x=  increase(x).ToString();
                y = Convert.ToInt32(increase(y));
                MessageBox.Show(x);
                MessageBox.Show(y.ToString()); }  private object increase(object    x)
            {
                if (x.GetType().Name.ToLower() == "string")
                    x = "QQ";
                else
                    x = 13;
                return x;
            } 
      

  4.   

    若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字
      

  5.   

    方法的参数是ref,调用者也要显式使用ref~
      

  6.   

    若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字!!!引用型参数!!