using System;
using System.Collections.Generic;
using System.Text;namespace StructByValue
{
struct Student
{
private int _age;
public Student()
{
}
public int Age
{
get { return _age; }
set { _age = value; }
}
} class Program
{
static void Main(string[] args)
{
//Student student = new Student(20);
Student student=new Student();
student.Age = 20;
Console.WriteLine("更新年龄之前的结果是:{0}", student.Age);
Program.ChangeAge(student);
Console.WriteLine("更新年龄之后的结果是:{0}", student.Age); }
static void ChangeAge(Student student)
{
student.Age = 37;
} }
}
这样调用为什么输出的值怎么都是 20;
using System.Collections.Generic;
using System.Text;namespace StructByValue
{
struct Student
{
private int _age;
public Student()
{
}
public int Age
{
get { return _age; }
set { _age = value; }
}
} class Program
{
static void Main(string[] args)
{
//Student student = new Student(20);
Student student=new Student();
student.Age = 20;
Console.WriteLine("更新年龄之前的结果是:{0}", student.Age);
Program.ChangeAge(student);
Console.WriteLine("更新年龄之后的结果是:{0}", student.Age); }
static void ChangeAge(Student student)
{
student.Age = 37;
} }
}
这样调用为什么输出的值怎么都是 20;
{
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
}
static void ChangeAge(ref Student student)
{
student.Age = 37;
}
class Student
{
private int _age;
public Student()
{
}
public int Age
{
get { return _age; }
set { _age = value; }
}
}