您的位置:首页 > 编程语言 > C#

今天才搞清楚:原来在C#中对象作函数参数,是引用传递:)

2006-08-31 17:33 711 查看

using System;


using System.Collections.Generic;


using System.Text;




namespace ConsoleApplication6




...{


public class Program




...{


static void Main(string[] args)




...{


aaa obj = new aaa("yourname");


initAge(obj);


Console.WriteLine(obj.Age.ToString());




bbb obj2 = new bbb("yourname",10);


initAge2(obj2);


Console.WriteLine(obj2.Age.ToString());


}




public static void initAge(aaa obj)




...{


obj.Age = 26;


}


public static void initAge2(bbb obj)




...{


obj.Age = 26;


}




}




public class aaa




...{


private string _name;


private int _age;




public string Name




...{




get...{ return this._name; }




set...{ this._name = value; }


}


public int Age




...{




get ...{ return _age; }




set ...{ _age = value; }


}




public aaa(string name)




...{


this._name = name;


}




}




public struct bbb




...{


private string _name;


private int _age ;




public string Name




...{




get ...{ return this._name; }




set ...{ this._name = value; }


}


public int Age




...{




get ...{ return _age; }




set ...{ _age = value; }


}




public bbb(string name,int age)




...{


this._name = name;


this._age = age;


}




}






}



试一下上面的代码便知:——)

平时在写代码的过程中,一直都似是而非,今天才彻底搞清楚。别笑话我啊,唉,确实比较菜啊。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: