-1

Is it possible to access an object's properties multiple times without repeatedly typing the object name? For example:

Using myObject {
    .Name = "name";
    .Colour = "red";
    .Age = "99";
}

Rather than having to type out something like:

myObject.Name = "name";
myObject.Colour = "red";
myObject.Age = "99";
user247702
  • 23,641
  • 15
  • 110
  • 157
chumtoadafuq
  • 256
  • 5
  • 14

1 Answers1

2

Nope. VB.Net has a way, but not C#

EDIT:

It's worth pointing out, that there is an initialization shorthand that is somewhat similar

var object = new SomeObject {
    Property1 = "string",
    Property2 = 0,
    Property3 = true
}

This works only for initializations. Once an object is initialized, there's no shorthand to access properties.

Carlos Rodriguez
  • 2,190
  • 2
  • 18
  • 29