哪一个更好?在类中声明成员变量或返回方法的参数?性能方面哪个更好。
class A{
//Declaring member variable
private string name;
private int age;
private method Display()
{
Passing();
Console.Write("{0}-{1}",name,age);
}
private void Passing()
{
name = "Hello World";
age = 21;
}
}
或者
class A{
//out parameter implementation
private method Display()
{
string name= string.Empty;
int age = 0;
Passing(out name,out age);
Console.Write("{0}-{1}",name,age);
}
private void Passing(out string name,out int age)
{
name = "Hello World";
age = 21;
}
}