-1
 Type typesample = packet.GetType();

Then I want to new an object in the type of typesample

Ka Res
  • 311
  • 2
  • 3
  • 17
jack Chen
  • 11
  • 8

2 Answers2

0

You can use

var instance = Activator.CreateInstance(typesample);
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
0

You can instantiate the type by using the Activator class:

var item = Activator.CreateInstance(typesample);
Chrille
  • 1,435
  • 12
  • 26