1

PHP :

if(($a = $toto) == 'test') echo $a;

VB.net

Dim a as string = toto
if a.equals("test") then console.writeline(a)

I like the "one line" code design, so, is it possible to do that in vb.net ?

4
  • Is 'toto' another variable and you want to see if both 'a' and 'toto' equal "test"? Commented Jun 7, 2013 at 5:50
  • 2
    php allows you to declare and initialize a variable (here $a) inside the body of if block, and the variable continues to exist after the block ends. vb doesn't. vb also does not allow you to declare variable in the conditional. in vb it is invalid to say: If (Dim a = toto) Then doSomething(). No shortcuts here. Commented Jun 7, 2013 at 6:01
  • @Alexander : yes, toto is another variable. Commented Jun 7, 2013 at 6:34
  • @inquisitive, [code]If (Dim a = toto) Then doSomething()[/code] is exactly what i wanna do. Too bad it's impossible. Commented Jun 7, 2013 at 6:35

2 Answers 2

2

It would be multi-liners instead like this instead

    Dim a As String = "test"
    Dim b As String = a

    if (b.equals("test")) then  console.writeline(b) 

Or as Alexander suggested you could use one liner like this (which actually not really one liner in the compiler most likely)

    Dim a As String = "test", b As String = a

    if (b.equals("test")) then  console.writeline(b) 
Sign up to request clarification or add additional context in comments.

3 Comments

That's it then! I'd like to add this link for reading: msdn.microsoft.com/en-us/library/ke6sh835(v=vs.110).aspx
Still two lines. I think it's not possible to do this in one line.
Yes @cyrianox it's not possible.
0

You Can use the following......

I haven't done it but I hope it will help u ..

Option Explicit Off

Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)       Handles Button1.Click
        If ((ss = "test") = "test") Then MessageBox.Show("hi")
    End Sub
End Class

1 Comment

Interesting, but i will not use Option Explicit off. Too dangerous :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.