확장메서드

장장·2025년 9월 22일

확장메서드 동영상강의

확장메서드 (Extention Method)

//추가 기능들을 제작하기 위한 보조 클래스를 생성
static class ExtentionMethods
{
    public static int CountChar(this string sourceText, char targetChar)
    {
        int count = 0;
        foreach (char c in sourceText)
        {
            if (c == targetChar) count++;
        }
        return count;
    }
}

static void Main(string[] args)
{
    string text = "Develoket";
    int count = text.CountChar('e');
    Console.WriteLine(count);
}

0개의 댓글