if (humanResourceManager.IsEmployeeExistByDepartmentNameAndNo(depname, employeeNo))
{
Employee employee = humanResourceManager.GetEmployeeExistByNo(employeeNo);
Employee[] employees = humanResourceManager.GetDepartmentByName(depname).Employees;
employee = null;
Array.Sort(employees);
Array.Reverse(employees);
while (employees[employees.Length - 1] == null)
{
Array.Resize(ref employees, employees.Length - 1);
}
Console.WriteLine("Silindi!");
}
将变量设置为null
不会改变对象被引用/使用的任何其他位置。请看下面的例子:
string s = "abc";
string c = s;
string c = null;
这不会改变变量s
,它仍然引用字符串对象"abc"
(但变量c
现在具有值null
)。数组也是如此:
string[] data = new string[] {"abc", "def", "ghi"};
string c = data[1];
string c = null;
同样,您只更改了变量c
,但没有更改数组data
。当你想改变数组时,你必须使用data
数组,像这样:
string[] data = new string[] {"abc", "def", "ghi"};
data[1] = null;
// the array is now: ["abc", null, "ghi"]
在您的情况下,您必须更改Employee[] employees
数组。根据您的代码,您可能需要使用humanResourceManager
中的方法来更新数组来自何处的源数据。