Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using ToString in VB.NET code in ASP.NET Web Page
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
ASP.NET
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01435079
Message ID:
01435142
Views:
49
Hi,
There's no magic about this.
Just remember that ToString() is a method of the System.Object class and Decimal is a Struct (which inherits from Object)
The default return value of ToString() is the name of the object but this is overridden in a lot of .NET classes to provide a more useful result. This why code such as 'string s = 3.ToString()' works. (simplified - since boxing/unboxing overhead comes into play)

It's worth looking at the other methods of Decimal (but most are Static):
http://msdn.microsoft.com/en-us/library/system.decimal_members.aspx

Also bear in mind that it often makes sense to override ToString() in your own classes.
HTH,
Viv

>Why is it that this works with the numerical value of the variable BMI (without the ToString), as well as BMI.ToString ? See below near bottom for lblBMI.Text.
>
>
>Partial Class BMICalculator
>    Inherits System.Web.UI.Page
>
>    Protected Sub CalculateBMI_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalculateBMI.Click
>        ' Find out the person's height and weight
>        Dim UsersHeight As Integer = txtHeight.Text
>        Dim UsersWeight As Integer = txtWeight.Text
>
>        ' Calculate the person's BMI.
>        Dim BMI As Decimal
>        BMI = (UsersWeight / (UsersHeight * UsersHeight)) * 703
>
>        ' Output the BMI value.
>        lblBMI.Text = "Your BMI is " & BMI.ToString
>    End Sub
>End Class
>
Previous
Reply
Map
View

Click here to load this message in the networking platform