这是我的课:
public class UserInformation
{
public string Username { get; set; }
public string ComputerName { get; set; }
public string Workgroup { get; set; }
public string OperatingSystem { get; set; }
public string Processor { get; set; }
public string RAM { get; set; }
public string IPAddress { get; set; }
public UserInformation GetUserInformation()
{
var CompleteInformation = new UserInformation();
GetPersonalDetails(ref CompleteInformation);
GetMachineDetails(ref CompleteInformation);
return CompleteInformation;
}
private void GetPersonalDetails(ref UserInformation CompleteInformation)
{
}
private void GetMachineDetails(ref UserInformation CompleteInformation)
{
}
}
我的印象是 ref 关键字告诉计算机使用相同的变量而不是创建一个新变量。
我是否正确使用它?我必须在调用代码行和实际方法实现上都使用 ref 吗?