C# 为什么不从employees数组中删除my employee对象?(不要介意我的方法)

C# 为什么不从employees数组中删除my employee对象?(不要介意我的方法),c#,C#,将变量设置为null不会更改引用/使用对象的任何其他位置。请参见以下示例: if (humanResourceManager.IsEmployeeExistByDepartmentNameAndNo(depname, employeeNo)) { Employee employee = humanResourceManager.GetEmployeeExistByNo(employeeNo); Employe

将变量设置为
null
不会更改引用/使用对象的任何其他位置。请参见以下示例:

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!");

                
            }
这不会更改变量
s
,它仍然引用字符串对象
“abc”
(但变量
c
现在的值为
null
)。阵列也是如此:

string s = "abc";
string c = s;
string c = null;
同样,您只更改变量
c
,但不更改数组
数据
。当您要更改数组时,必须使用
数据
数组,如下所示:

string[] data = new string[] {"abc", "def", "ghi"};
string c = data[1];
string c = null;

在您的情况下,必须更改
Employee[]employees
数组。根据您的代码,您可能需要使用
humanResourceManager
中的方法来更新数组来自的源数据。

Employee[]employees=humanResourceManager.GetDepartmentByName(depname).employees.where(z=>z!=Employee.ToArray()
string[] data = new string[] {"abc", "def", "ghi"};
data[1] = null;
// the array is now: ["abc", null, "ghi"]