cast class into another class or convert class to another

前端 未结 9 648
逝去的感伤
逝去的感伤 2020-11-28 22:29

my question is shown in this code

I have class like that

public class  maincs
{
  public int a;
  public int b;
  public int c;
  public int d; 
}
         


        
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 23:21

    Using this code you can copy any class object to another class object for same name and same type of properties.

    JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); 
    string serializeString = JsonConvert.Serialize(objectEntity);
    objectViewModel objVM = JsonConvert.Deserialize(serializeString);
    

提交回复
热议问题