Home > Net >  Know what type, but this type is to know the variable name, and then how to define a variable with h
Know what type, but this type is to know the variable name, and then how to define a variable with h

Time:05-24


The custom data binding model, know the parameter name and type of the interface, but how to use this type and define a variable, the following code
 var typeName=bindingContext. ModelMetadata. ModelType. Name; 
The Type T=the GetType (typeName);


Now I want to use T this type defines a variable, or so

T HouseModel=new T ();

But I don't know have this aspect of the c # syntax errors, grammar, consult tall person to give directions, thank you very much!

CodePudding user response:

The Activator. Createinstance (type);
Create an instance of a class as directed by the type

CodePudding user response:

reference 1st floor xuzuning response:
the Activator. The Createinstance (type);
Create an instance of a class as directed by the type


Not very understand, can be simple, for example

CodePudding user response:

The
refer to the original poster goodgame365 response:
custom data binding model, know the parameter name and type of the interface, but how to use this type and define a variable, the following code
 var typeName=bindingContext. ModelMetadata. ModelType. Name; 
The Type T=the GetType (typeName);


Now I want to use T this type defines a variable, or so

T HouseModel=new T ();

But I don't know have this aspect of the c # syntax errors, grammar, consult tall person to give directions, thank you very much!


Get type, first instantiated, materialization object, is your class variables,
  •  Tags:  
  • C#
  • Related