• Saves Valuable Time
  • Trusted Accuracy for 14 Years
  • 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# and Instant VB to convert between VB.NET and C#.     

Additional resource: VB.NET and C# Equivalents

Copyright © 1997 – 2018 Tangible Software Solutions Inc.