locked
pass data from model to another model RRS feed

  • Question

  • User-1016473172 posted

    Lets say I have

    I have one model class here: 

    public class carone
    {
    public string greencar { get; set; }
    }

    second class model

    public class cartwo
    {
    public string redcar { get; set; }
    }

    without doing:

    public class carone
    {
    public string greencar { get; set; }
    public string redcar { get; set; } }

    And I want pass the data from model 1 to model class 2.
    How do I achive that?


    Tuesday, November 3, 2020 10:54 PM

All replies

  • User-1330468790 posted

    Hi arclite860,

     

    Could you please specify the scenario that you meet this problem?

    I am afraid that I don't get the point the question. If you want to pass the value to another model, which value should be passed? 

    From my understanding, you just need to assign the value from the property "greencar" of the class "carone" to the property "redcar" of the class "cartwo".

    For example, 

                carone carone = new carone() { greencar = "car1" };
                cartwo cartwo = new cartwo() { redcar = "car2" };
                Console.WriteLine("The redcar value of the cartwo is : {0}",cartwo.redcar);
    
                cartwo.redcar = carone.greencar;
                Console.WriteLine("The redcar value of the cartwo is : {0}", cartwo.redcar);
    
                Console.ReadLine();

    Console Result:

    The redcar value of the cartwo is : car2
    The redcar value of the cartwo is : car1

    However, obviously what you are asking might be another question.

    It would be easier to understand the question with more illustration.

     

    Thank you for understanding.

    Best regards,

    Sean

    Wednesday, November 4, 2020 2:01 AM