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.

56<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>C# ConVarusing System;public partial class ConVar : System.Web.UI.Page{private const int VAGE = 18;private int yourAge;private int legalAge;protected void Page_Load(object sender, EventArgs e){yourAge = Convert.ToInt16(YourAge.Text);legalAge = yourAge - VAGE;YourAge.Text = Convert.ToString(legalAge);}}That exact script returns the value of 1. That’s because the Label object namedYourAge has a Text value of “19,” and while a string, it is converted to an integer bythe C# portion of the class. Try changing the value of 19 to something else relative to theconstant’s value of 18. You can then get a negative number.Naming ConventionsNaming conventions are just that—conventions. They are not rules, so your nameselection may be unique, not follow conventions, and everything may still work just fine.However, I find that a consistent set of naming conventions is quite helpful, and you willfind that once you have a standard set, you and others can understand your code muchbetter. One of the areas where things get murky in naming conventions is with constants.In most languages, constants have been written in all caps. In the previous example,VAGE is an example of a constant name following the convention of using all uppercasefor constants. Depending on which convention article you read and the date, you willfind different conventions suggested for constant names in C#. The following are somedifferent applied conventions:●●All caps This convention uses all uppercase letters. It is only to be used for constantsand SQL <strong>com</strong>mands. For example, FREEZEPOINT is a typical identifier when usingconstants.Camel case Also called “mixed case” or “inter case,” this naming conventionjoins words without using spaces or underscores. The first letter is lowercase, hencethe name camel for the hump where an uppercase letter appears. For example,firstName is a variable that uses camel case.

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

Saved successfully!

Ooh no, something went wrong!