DreamTeK
DreamTeK

Reputation: 34307

Setting a boolean if equals true/false in ASP.NET

In VBA I have used similar code to below to set a boolean value, is there a way to accomplish somthing similar in .NET using shorthand?

Dim A As Boolean
Dim B As Integer
Dim C As Integer

A = B = C

Set A to true or false if B equals C

The full statement would be:

If B = C Then
  A = True
Else
  A = False
End If

Upvotes: 0

Views: 1705

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27342

Yes you can just write (in VB.NET) A = B = C

That works in the way you expect. I would suggest that you add some brackets to improve readability:

A = (B = C)

Also make sure you have Option Strict On to avoid type conversion errors that are difficult to spot.

In C# you would have to write:

A = (B == C);

Upvotes: 3

Related Questions