tags:

views:

1754

answers:

3
+11  A: 

Not really, you have to assign a variable. So

    Stuff.Elements.Foo bar;
    bar.Name = "Bob Dylan";
    bar.Age = 68;
    bar.Location = "On Tour";
    bar.IsCool = True;

Or in C# 3.0:

    var bar = new Stuff.Elements.Foo
    {
        Name = "Bob Dylan",
        Age = 68,
        Location = "On Tour",
        IsCool = True
    };
Robert Harvey
You are treating 'Stuff.Elements.Foo' as a type. Is that how it is being used in the VB code, or is it actually a reference to a nested variable? The technique is perfectly valid but I think your code isn't quite right.
quark
+2  A: 

The closest thing in C# 3.0, is that you can use a constructor to initialize properties:

Stuff.Elements.Foo foo = new Stuff.Elements.Foo() {Name = "Bob Dylan", Age = 68, Location = "On Tour", IsCool = true}
foson
You are treating 'Stuff.Elements.Foo' as a type. Is that how it is being used in the VB code, or is it actually a reference to a nested variable? The technique is perfectly valid but I think your code isn't quite right. (I've copied quark's comment here as it applies to this answer too)
MarkJ
+3  A: 

Aside from object initializers (usable only in constructor calls), the best you can get is:

var it = Stuff.Elements.Foo;
it.Name = "Bob Dylan";
it.Age = 68;
...
Pavel Minaev