Author: Svetlin Nakov
Pub Date: 2013
Size: 10 Mb
The book “Fundamentals of Computer Programming with C#” is a comprehensive computer programming tutorial that teaches programming, logical thinking, data structures and algorithms, problem solving and high quality code with lots of examples in C#. It starts with the first steps in programming and software development like variables, data types, conditional statements, loops and arrays and continues with other basic topics like methods, numeral systems, strings and string processing, exceptions, classes and objects. After the basics this fundamental programming book enters into more advanced programming topics like recursion, data structures (lists, trees, hash-tables and graphs), high-quality code, unit testing and refactoring, object-oriented principles (inheritance, abstraction, encapsulation and polymorphism) and their implementation the C# language. It also covers fundamental topics that each good developer should know like algorithm design, complexity of algorithms and problem solving.
So why the code works when the property is used instead of the field? The key to the answer to the question gives a compiler error: if we want to modify an instance of the structure, it must be done through the variable. In C # variable represents a memory location, and if we refer to a specific field by name, it is clear that we want to apply to the memory cell that contains the value. However, the methods (and consequently, the properties) can not return anything that would represent memory location – they are able to return only contained in the memory cell value. In other words, C # does not provide the equivalent of the ref keyword for the return values. Fortunately, almost all value types are immutable, and this problem occurs only when using a mutable value types.
Indexer – a property that takes one or more arguments and which can be accessed using the array access syntax. This is useful when creating a class that contains a collection of objects. The code in Listing uses one of the collection classes provided by the .NET Framework. In fact, it is an array of variable length; but thanks to the indexer, which is used here in the second and third lines, the impression of using the native array.
From the standpoint of environmental CLR, the indexer is a common feature of most, but with the difference that it is designated as the default properties. This concept is part of the .NET transferred to the legacy of the old versions of Visual Basic on the basis of COM that is largely ignored in C #. Indexers are the only element of the C # treats default properties in a special way. If the class is assigned to the property as the default property and if it takes at least one argument, C # allow access this property by using the syntax of the indexer.