我在下面的代码片段中总结了我的问题。值类型和参考类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
public class Student
{
public int Marks { get; set; }
public Student(int marks)
{
this.Marks = marks;
}
public void AssignMarks(Student st)
{
st = null;
}
public void AssignMarks(ref Student st)
{
st = null;
}
}
class Program
{
static void Main(string[] args)
{
Student st = new Student(50);
st.AssignMarks(st);
Console.WriteLine(st.Marks);
Student st1 = new Student(50);
st.AssignMarks(ref st1); // NullReferenceException
Console.WriteLine(st1.Marks);
}
}
}
为什么我上标有**
好吧,异常的类型可能有所帮助 – BlackICE 2010-12-08 15:35:48
我编辑了我的问题。我得到NullReferenceException – 2010-12-08 15:38:15