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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

58<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>All this <strong>ASP</strong>X file does is to provide a convenient TextBox form for output for a variableto be defined in the C# portion. The C# portion is where you can see definite assignmentat work (or not). First, look at a perfectly well-formed definite assignment for the stringvariable stVar.using System;public partial class DefAssn : System.Web.UI.Page{private string stVar;protected void Page_Load(object sender, EventArgs e){stVar = "Test";Show.Text = stVar;}}When that runs, you will see the value Test appear in the text box window. If you<strong>com</strong>ment out the line//stVar = "Test";everything still works fine. Nothing appears in the text box window, but the <strong>com</strong>pilerdoesn’t throw an error. However, if you <strong>com</strong>ment out the line//private string stVar;and leave in the statement that provides the variable with the value Test, you will getan error. That’s because the variable has not been declared. If you declared a variable inC# but did not assign it a value (initialize it) prior to using it, you will get an error. So,while it’s an important practice to keep in mind, output to an <strong>ASP</strong>.<strong>NET</strong> form is a bit moreforgiving than to a C#-only program that outputs to the System.Console.WriteLineor some similar non-<strong>ASP</strong>.<strong>NET</strong> structure.Operators and PunctuatorsC# uses a full set of operators to state the relations between elements in expressions.Likewise, a set of punctuators sets demarcations between different units in statements.Those unfamiliar with operators can think of them as verbs and the different elements

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

Saved successfully!

Ooh no, something went wrong!