일반적으로 코드 중복을 줄이기 위해 내부 전용 메서드가있는 클래스를 만들 때 인스턴스 필드를 사용할 필요가없는 경우 메서드를 정적으로 선언하면 성능이나 메모리 이점이 있습니까?
예:
foreach (XmlElement element in xmlDoc.DocumentElement.SelectNodes("sample"))
{
string first = GetInnerXml(element, ".//first");
string second = GetInnerXml(element, ".//second");
string third = GetInnerXml(element, ".//third");
}
...
private static string GetInnerXml(XmlElement element, string nodeName)
{
return GetInnerXml(element, nodeName, null);
}
private static string GetInnerXml(XmlElement element, string nodeName, string defaultValue)
{
XmlNode node = element.SelectSingleNode(nodeName);
return node == null ? defaultValue : node.InnerXml;
}
GetInnerXml () 메서드를 정적으로 선언하면 어떤 이점이 있습니까? 의견이 없습니다. 의견이 있습니다.