13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

54<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>The rest of the method converts data entered as string to real numbers to be used in thecalculations. For example, the C# lines1 = Convert.ToDouble(ScoreA.Text) * .85;takes whatever was entered into the TextBox in the <strong>ASP</strong>.<strong>NET</strong> portion of the classinto a number (a double) and assigns the value to the variable s1. Included is themultiplication of the text from <strong>ASP</strong>.<strong>NET</strong> that has to be converted to a floating-pointnumber (the double type in this case) by .85. The TextBox field with the referencename (ID) of ScoreA originated in the linein <strong>ASP</strong>.<strong>NET</strong>.Going in the opposite direction, to output the results of the multiplication and additionto the Total Label field, the numeric values have to be re-converted to text as thefollowing C# line shows:Total.Text = Convert.ToString(s1 + s2);So, in the same way that the Convert class uses the ToDouble method to convertfrom a string to a number, ToString converts back to a string that can be used in aLabel output form. Think of it as a roundtrip beginning with the <strong>ASP</strong>.<strong>NET</strong> structures andthe C# engine kick-starting the user events or events from some other state in the program.Basic C# StructuresIn this section, we’re going to look at the basic C# structures independent of <strong>ASP</strong>.<strong>NET</strong>. Thenin the examples, you will see how these structures are used in conjunction with <strong>ASP</strong>.<strong>NET</strong> ina partial class. However, for the time being this section focuses on the C# structures.Variables and ConstantsAs implied in the previous sections in this chapter, a variable is a container-like structureused to store data. The data in the container can change in value—it varies; hence, theterm variable. As you saw in the previous discussion, you need to provide variables witha type, and you cannot pass the value of one variable type to a variable of a differentvariable type. So, if you place a decimal value into a decimal type variable, you’ll findeverything works fine. Further, if you place the value of one variable into another of thesame type, your program works.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!