−So far in [[C Sharp Essentials|C# Essentials]] we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is more more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.
+So far in [[C Sharp Essentials|C# Essentials]] we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.
C# provides extensive support for developing object-oriented applications. The subject area of object oriented programming is, however, large. It is not an exaggeration to state that entire books could be dedicated to the subject (because entire books ''have'' been dedicated to the subject). As such, a detailed overview of object oriented software development is beyond the scope of [[C Sharp Essentials|C# Essentials]]. Instead, we will introduce the basic concepts involved in object oriented programming and then move on to explaining the concept as it relates to C# application development.
C# provides extensive support for developing object-oriented applications. The subject area of object oriented programming is, however, large. It is not an exaggeration to state that entire books could be dedicated to the subject (because entire books ''have'' been dedicated to the subject). As such, a detailed overview of object oriented software development is beyond the scope of [[C Sharp Essentials|C# Essentials]]. Instead, we will introduce the basic concepts involved in object oriented programming and then move on to explaining the concept as it relates to C# application development.
Before an object can be instantiated we first need to define the class 'blueprint' for the object. In this chapter we will create a Bank Account class to demonstrate the concepts of C# object oriented programming.
Before an object can be instantiated we first need to define the class 'blueprint' for the object. In this chapter we will create a Bank Account class to demonstrate the concepts of C# object oriented programming.
−A C# class is declared using the ''public class'' keywords followed by the name of the class. Although the C# compiler will accept just about nay name for a class, programming convention dictates that a class name begin with a capital letter:
+A C# class is declared using the ''public class'' keywords followed by the name of the class. Although the C# compiler will accept just about any name for a class, programming convention dictates that a class name begin with a capital letter:
<pre>
<pre>
== Creating C# Class Members ==
== Creating C# Class Members ==
−Class members or properties are essentially variables and methods embedded into the class. Members can be ''public'', ''private'' or protected.
+Class members or properties are essentially variables and methods embedded into the class. Members can be ''public'', ''private'' or ''protected''.
''public'' members can be accessed from outside the object and are also visible in classes derived from the current class. ''private'' members can only be accessed by methods contained in the class and are not accessible to derived classes. ''protected'' classes are only available to derived classes.
''public'' members can be accessed from outside the object and are also visible in classes derived from the current class. ''private'' members can only be accessed by methods contained in the class and are not accessible to derived classes. ''protected'' classes are only available to derived classes.
−This the key to what is called ''data encapsulation''. Object-oriented programming convention dictates that data should be encapsulated in the class and accessed and set only through the methods of the class (typically called ''getters'' and ''setters'').
+This is the key to what is called ''data encapsulation''. Object-oriented programming convention dictates that data should be encapsulated in the class and accessed and set only through the methods of the class (typically called ''getters'' and ''setters'').
We can now extend our BankAccount class to add member variables to hold the account name and number. True to the concept of data encapsulation we will be making some of these creating members ''private'' and writing methods to access these values later:
We can now extend our BankAccount class to add member variables to hold the account name and number. True to the concept of data encapsulation we will be making some of these creating members ''private'' and writing methods to access these values later:
== Accessing C# Object Members ==
== Accessing C# Object Members ==
Exception encountered, of type "Error"
[b70f6642] /index.php?diff=prev&oldid=4800&title=C_Sharp_Object_Oriented_Programming Error from line 434 of /var/www/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /var/www/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /var/www/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /var/www/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /var/www/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /var/www/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /var/www/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /var/www/techotopia/includes/diff/TableDiffFormatter.php(194): WordLevelDiff->__construct()
#7 /var/www/techotopia/includes/diff/DiffFormatter.php(140): TableDiffFormatter->changed()
#8 /var/www/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /var/www/techotopia/includes/diff/DifferenceEngine.php(881): DiffFormatter->format()
#10 /var/www/techotopia/includes/diff/DifferenceEngine.php(797): DifferenceEngine->generateTextDiffBody()
#11 /var/www/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /var/www/techotopia/includes/diff/DifferenceEngine.php(662): DifferenceEngine->getDiffBody()
#13 /var/www/techotopia/includes/diff/DifferenceEngine.php(632): DifferenceEngine->getDiff()
#14 /var/www/techotopia/includes/diff/DifferenceEngine.php(453): DifferenceEngine->showDiff()
#15 /var/www/techotopia/includes/page/Article.php(797): DifferenceEngine->showDiffPage()
#16 /var/www/techotopia/includes/page/Article.php(508): Article->showDiffPage()
#17 /var/www/techotopia/includes/actions/ViewAction.php(44): Article->view()
#18 /var/www/techotopia/includes/MediaWiki.php(490): ViewAction->show()
#19 /var/www/techotopia/includes/MediaWiki.php(287): MediaWiki->performAction()
#20 /var/www/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#21 /var/www/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#22 /var/www/techotopia/index.php(41): MediaWiki->run()
#23 {main}