XmlNode操作是否“按引用”? C#

This code works but I want to understand why I don't have the pass the modified XmlDocument back to the caller - a code review I guess ;). I assume that these operations within XmlNode are using "by Ref" internally to operate on the document. I can see that working but I just want to make sure I understand this correctly. I have not found any documentation that addresses this specifically - probably because it is so obvious. So help me out here fellow devs. This is all happening by Ref and I don't have to worry about passing the modified XmlDocument back to the caller correct? Also, is this thread safe? I am using this code as part of a service app.

public void AddNewElement(XmlDocument doc, string elementName)
{
    XmlNode selectedNode = doc.SelectSingleNode("//" + elementName);
    if (selectedNode == null)
    {
        var childNodes = doc.LastChild.LastChild.ChildNodes;
        XmlNode appendNode = childNodes.Item(childNodes.Count - 1);
        XmlNode newNode = appendNode.AppendChild(doc.CreateElement(elementName));
        newNode.InnerText = str64;
    }
}
评论