I want run my code bellow,but it says that I can not use varialbe as type,how can I implement?
- using System;
- using System.Linq;
- using System.Reflection;
- namespace Mike.ConsoleApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- #region this is ok
- Personal specifiedPersonal = new Personal();
- Employee
employee = new Employee (); - employee.DoSth();
- #endregion
- #region this would be error
- Assembly assmebly = typeof(Personal).GetTypeInfo().Assembly;
- Type dynamicType = assmebly.ExportedTypes.Where(x => x.Name == "Personal").FirstOrDefault();
- Employee
dynamicEmployee = new Employee (); - dynamicEmployee.DoSth();
- #endregion
- Console.ReadLine();
- }
- public class Personal
- {
- public string FirstName { get; internal set; }
- public string LastName { get; internal set; }
- }
- public class Employee
- {
- public void DoSth()
- {
- Console.WriteLine("Done !!!"); ;
- }
- }
- }
- }
John IwaszPosted Dec 17, 2018, 3:01 PM
Sreekanth ReddyPosted Dec 17, 2018, 12:28 AM