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 !!!"); ;
- }
- }
- }
- }

Sreekanth ReddyRank #726 · 3.2K reputationPosted Dec 16, 2018, 7:28 PM EST
John IwaszRank #811 · 2.8K reputationPosted Dec 17, 2018, 10:01 AM EST