비순수 함수와 순수 함수
비순수 함수
다음 코드에서 HypenatedConcat 함수는 클래스에서 aMember 데이터 멤버를 수정하기 때문에 순수 함수가 아닙니다.
public class Program
{
private static string aMember = "StringOne";
public static void HypenatedConcat(string appendStr)
{
aMember += '-' + appendStr;
}
public static void Main()
{
HypenatedConcat("StringTwo");
Console.WriteLine(aMember);
}
}
순수함수
class Program
{
public static string HyphenatedConcat(string s, string appendStr)
{
return (s + '-' + appendStr);
}
public static void Main(string[] args)
{
string s1 = "StringOne";
string s2 = HyphenatedConcat(s1, "StringTwo");
Console.WriteLine(s2);
}
}
이런것도 있었구나.