Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using ToString in VB.NET code in ASP.NET Web Page
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
ASP.NET
Database:
Visual FoxPro
Divers
Thread ID:
01435079
Message ID:
01435142
Vues:
48
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
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform