• Saves Valuable Time
  • Trusted Accuracy since 2004
  • 15-Day Money-Back Guarantee

C# Equivalent to VB With

With is considered by some to be poor programming practice because it obscures the enclosed code purely for the benefit of reduced typing of one object name during development - you can't see what object you're applying the With operator to from within in the middle of a long With block:

With SomeExtremelyLongNamedPersonObject
    .Name = "Zak"
    .Age = 50
    .Language = Language.English
End With

The closest that you can get in C# is to use a temporary variable with an abbreviated name, but this also obscures your code:

Person p = SomeExtremelyLongNamedPersonObject;
p.Name = "Zak";
p.Age = 50;
p.Language = Language.English;

Use Instant C# to convert from VB.NET to C#.     

Additional resource: VB.NET and C# Equivalents

Copyright © 2004 – 2020 Tangible Software Solutions, Inc.