When I instantiate a new entity, it looks like this:
var myEntity = new MyEntity()
{
Field1 = "myValue",
Field2 = "myOtherValue",
...
}
This avoids having to write myEntity.Field1 many time.
But when I have to update multiple properties, I don’t know any way to avoid the repetition of code. So at the moment, I do like this:
myEntity.Field1 = "myNewValue";
myEntity.Field2 = "myOtherNewValue";
...
Does C# allow any more concise way of updating multiple properties?
Check out the C# with keyword equivalent. It’s a bit sloppy, but it is the closest you can get to the VB.NET With statement.
Also take a look at this blog post: Simple equivalent of “With” statement in C#