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.

Chapter 4: Doing More with C# and <strong>ASP</strong>.<strong>NET</strong> 93{}private string myProperty;public MyClass(){myProperty = "Some value";}public string MyMethod(string paramName){return myProperty + paramName}If you’ve used Java, the format should be fairly familiar. Some other languages, likeActionScript 3.0, use the keyword function for methods, but the general approach isthe same. To get a better idea of how to create a pure C# class in an <strong>ASP</strong>.<strong>NET</strong> environmentin Microsoft Visual Studio 2008, the next section provides a simple example.Mutators and AccessorsIn general, you should use mutators and accessors (also known as “getters” and “setters”)with private properties. You would use accessors to get the value of a property andmutators to set a value. By doing so, you further encapsulate a variable. However, tokeep the C# functions in the <strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong> web sites relatively short, accessors will notbe used here. To employ a getter/setter model, use the format:MyVar{}get{}set{}return myVar;myVar = value;However, as a reminder of good practices, most of the variables are defined as privateeven though the getter/setter functions are not used.

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

Saved successfully!

Ooh no, something went wrong!