Arsalan
Arsalan

Reputation: 744

Declaring parameter when passing to a Function in VB.NET

we have something like this in C#:

public static int ToInt<T>(this T obj) =>
       int.TryParse(obj,out int result)?result: -1;

we can declared result when we passing that to TryParse method, is there an equivalent way in vb.NET?

Upvotes: 0

Views: 338

Answers (2)

Joseph Wu
Joseph Wu

Reputation: 5028

you may try:

            Dim result As Integer = If(Integer.TryParse(obj, result), result, -1)
            Return result

Upvotes: 2

Paul Kertscher
Paul Kertscher

Reputation: 9742

Inline declarations came to C# with the Version 7.0. VB.NET 15 has been released around the same time.

According to this blog post, inline declarations did not make it to VB.NET 15. (See the section Language Features that Were Left Out of Visual Basic 15)

EDIT

Apparently VB.NET does not even have the out paramter modifier at all. The closest equivalent would be ByRef, which is really more like C#s ref, which does not support inline declarations, too.

Upvotes: 0

Related Questions