Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Visual Basic 'With' analog in C#? [duplicate]

Possible Duplicate:
C# equivalent for Visual Basic keyword: 'With' ... 'End With'?

VB.NET

With Alpha.Beta.Gama.Eta.Zeta
    a = .ZetaPropertyA
    b = .ZetaPropertyB
    c = .ZetaPropertyC
End With

C#?

a = Alpha.Beta.Gama.Eta.Zeta.ZetaPropertyA
b = Alpha.Beta.Gama.Eta.Zeta.ZetaPropertyB  
c = Alpha.Beta.Gama.Eta.Zeta.ZetaPropertyC
like image 573
serhio Avatar asked Dec 01 '22 04:12

serhio


2 Answers

Nope, doesn't exist.

Though you could shorten it a bit:

var z = Alpha.Beta.Gama.Eta.Zeta;

z.ZetaPropertyA = a;
z.ZetaPropertyB = b; 
z.ZetaPropertyC = c;

for your other case:

var z = Alpha.Beta.Gama.Eta.Zeta;

a = z.ZetaPropertyA;
b = z.ZetaPropertyB;
c = z.ZetaPropertyC;

That should've been obvious though ;)

like image 75
Femaref Avatar answered Dec 03 '22 16:12

Femaref


For new instances you can use object initializer:

Alpa.Beta.Gama.Eta = new Zeta
{
    ZetaPropertyA = a, 
    ZetaPropertyB = b,
    ZetaPropertyC = c
}
like image 39
Jakub Konecki Avatar answered Dec 03 '22 17:12

Jakub Konecki