Console.WriteLine arguments?

TechTeach

New member
Joined
Jan 4, 2013
Messages
4
Programming Experience
Beginner
Hello All,

I have been researching and trying to figure out why the first WriteLine isn't printing out the entire line when I debug the code. I'm sure I am missing something really silly but I just can't figure it out. Can somebody please explain to me why the C in the first line isn't printing out when I debug ... System.Console.WriteLine("The answer is", C)


VB.NET:
Module Module1

    Sub Main()


        Dim A As Integer = 2
        Dim B As Integer = 10
        Dim C As Integer


        Try
            C = B / A
            System.Console.WriteLine("The answer is", C)
            System.Console.WriteLine(C)
            System.Console.WriteLine("Press Enter to continue...")
            Console.ReadLine()
        Catch e As OverflowException
            System.Console.WriteLine("An overflow exception occured.")
            System.Console.WriteLine("Press Enter to continue...")
            System.Console.ReadLine()
        End Try


    End Sub


End Module
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,726
Location
Sydney, Australia
Programming Experience
10+
Because that overload of WriteLine takes a format string and values to insert into that format string. Your format string contains no parameter place-holders so the value you specify will not be inserted into it. That code should keep using the same overload and include a place-holder to replace with the value:
VB.NET:
Console.WriteLine("The answer is {0}.", C)
or it should use a different overload that simply takes a single string to be output as is:
VB.NET:
Console.WriteLine("The answer is " & C & ".")
 
Top Bottom