Hello I would like to ask about this code:
Edit: The class is immutable, I make it auto-property instead of private.
public class Person {
public int Id { get; }
public string Name { get; }
public string Title { get; }
public int Age { get; }
public Image Picture { get; }
.... // lot of other fields
private string Address { get; }
public Person(int id, string name, ...) {
// usual constructor init
}
}
var John = new Person(1, "John", "Mr.", 54, ... );
Now I would like to create a new person (without mutation) based on John, only small modification on some fields, such as name and age.
In Javascript I could do something like this:
let bob = Object.assign({}, john, {name: "bob", age: 55};
How to return a new object with little modification in C#?
// something like this?
var Bob = Person.From(John, name: "Bob", age: 55);