프로그래밍/C#

c# string으로 class 인스턴스 생성하기

JinFluenza 2017. 9. 4. 18:11

namespace ConsoleApplication5
{
    class Test
    {   
        public void Print()
        {
            Console.WriteLine("?");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {

                                               //네임스페이스.클래스명
            Type type = Type.GetType("ConsoleApplication5.Test");
            Test instance = Activator.CreateInstance(type) as Test;
            instance.Print();

        }    
    }
}