본문 바로가기
프로그래밍/C#

C# Generic return T

by neive 2022. 10. 2.
728x90
    public T GetGenericReturn<T>(string num)
    {
        return (T)Convert.ChangeType(num, typeof(T));
    }
    
    int n = GetGenericReturn<int>("1");
    string n = GetGenericReturn<string>("1");

 

 한개의 함수로 그때 그때 다른 리절트를 얻는

728x90

댓글