C#中对象作函数参数的详细介绍
C#中对象作函数参数的详细介绍
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceConsoleApplication6
{
publicclassProgram
{
staticvoidMain(string[]args)
{
aaaobj=newaaa("yourname");
initAge(obj);
Console.WriteLine(obj.Age.ToString());
bbbobj2=newbbb("yourname",10);
initAge2(obj2);
Console.WriteLine(obj2.Age.ToString());
}
publicstaticvoidinitAge(aaaobj)
{
obj.Age=26;
}
publicstaticvoidinitAge2(bbbobj)
{
obj.Age=26;
}
}
publicclassaaa
{
privatestring_name;
privateint_age;
publicstringName
{
get{returnthis._name;}
set{this._name=value;}
}
publicintAge
{
get{return_age;}
set{_age=value;}
}
publicaaa(stringname)
{
this._name=name;
}
}
publicstructbbb
{
privatestring_name;
privateint_age;
publicstringName
{
get{returnthis._name;}
set{this._name=value;}
}
publicintAge
{
get{return_age;}
set{_age=value;}
}
publicbbb(stringname,intage)
{
this._name=name;
this._age=age;
}
}
}
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceConsoleApplication6
{
publicclassProgram
{
staticvoidMain(string[]args)
{
aaaobj=newaaa("yourname");
initAge(obj);
Console.WriteLine(obj.Age.ToString());
bbbobj2=newbbb("yourname",10);
initAge2(obj2);
Console.WriteLine(obj2.Age.ToString());
}
publicstaticvoidinitAge(aaaobj)
{
obj.Age=26;
}
publicstaticvoidinitAge2(bbbobj)
{
obj.Age=26;
}
}
publicclassaaa
{
privatestring_name;
privateint_age;
publicstringName
{
get{returnthis._name;}
set{this._name=value;}
}
publicintAge
{
get{return_age;}
set{_age=value;}
}
publicaaa(stringname)
{
this._name=name;
}
}
publicstructbbb
{
privatestring_name;
privateint_age;
publicstringName
{
get{returnthis._name;}
set{this._name=value;}
}
publicintAge
{
get{return_age;}
set{_age=value;}
}
publicbbb(stringname,intage)
{
this._name=name;
this._age=age;
}
}
}