Something that is abstract does not have a "proper" existence. When writing programs, the word abstract means an idealized description of an object. An abstract class contains descriptions of things that need to be present, but it does not say how the program is to realize them. In C#, a class is abstract if marked as such, or if it contains one or more methods marked as abstract.

You can't create an instance of an abstract class, but you can use it as the basis of, or template for, a concrete one. For example, you may decide that you need many different kinds of receipts in a transaction processing system, such as cash, check, and wholesaler. You don't know how each particular receipt will work internally but you do know those behaviors that a receipt must have.

You can therefore create an abstract Receipt class that serves as the basis of all the concrete ones. You create each concrete receipt class by extending the abstract parent one. Thus, it is a member of the receipt family (that is, the program treats it as a Receipt), but it works in its own way.

You can create references that have an abstract type; such a reference can refer to an instance of any of the classes descended from the abstract parent.


In the .NET Framework, an assembly is a collection of executable code and program resources that you can deploy onto a target. Microsoft Visual Studio 2005 will create assemblies as the output from projects. If an assembly has an entry point, it will be an executable assembly and have the file extension .exe. If an assembly does not have an entry point, you must use it as a library, and it will have the file extension .dll.

Programs running on the .NET Framework on a personal computer (PC) or a Smart-phone are linked together when they run. Library files are located and used as required as the program executes. When you build programs for the .NET Micro Framework, you download them in complete form into the target hardware.


An attribute is a special kind of class that you can use to add detail to a type, a method, or a property. You specify the attribute in front of the declaration of the item.

 [RobsAttribute] class DataReading { } 

You can create your own attribute classes by extending the System.Attribute parent class. Programs that use reflection to discover information about a given item can also obtain instances of any attributes that have been attached. One use of attributes is as a tag to indicate that a class is serializable. The [Serializable] attribute does not add any other detail to an item.


The C# keyword base has different meanings depending on where it appears, but it always appears in the context of a child class that is extending a parent. You can use it in the construction of an instance of a child class to call the constructor in the parent. You can also use it in a method that overrides one in the parent; in this case, you use it to call the overridden method.


A cast is a way of forcing the compiler to regard a reference as referring to a particular type. Many collection classes manage the things they work on by references to objects because this means they can work on any type.

However, when you have your object reference and want to use it as the type it really is, you have to cast the reference to the type that you want to work with. You also use casting when you want to perform type conversion in a slightly simpler manner, for example, to take a value from a floating-point variable and place it in an integer (something that C# would not normally allow because it may result in a loss of data caused by removal of the fractional part of the value).

 double x = 3.6; int i = (int) x; 

The previous code transfers the double-precision value in x into i and discards the fractional part. Casting lets the programmer assume responsibility for type conversions that the compiler would otherwise reject. If they turn out to be unworkable, the run-time system will respond by throwing an exception. That is, casting a string to an int will make the program compile, but it will fail at runtime because the conversion is not meaningful.


A class is a collection of behaviors (methods) and data (properties). You can use it to represent a real-world item in your program (for example, a sensor reading) or an abstract item (for example, a transaction). Whenever you need to collect a number of things into a single unit, you should think in terms of creating a class.


A component is a class that exposes its behavior in the form of an interface. This means that rather than being thought of in terms of what it is (for example, a Front-WheelControl), it is thought of in terms of what it can do (implement the IDrive interface to receive methods to set speed and direction of movement). When creating a system, you should focus on the components and how they interact. You express their interactions in the interfaces between them.


A constructor is a method in a class that gets control when a program creates an instance of a class. It can receive parameters so that it can give initial values to members inside the instance. Overloading a constructor is possible; that is, there may be multiple constructor versions, each of which has a different signature and uses different combinations of initial values. A constructor cannot fail; it must either run to completion or throw an exception. If it completes, an instance of the class will be created. One constructor in a class may call another (useful if you want to make a single "master" constructor and then call it in different ways from the other overloads) by use of this. If a constructor is in a child class, and its parent has constructor methods, it must call one of the parent constructor methods by use of the base keyword.


A delegate is a type-safe reference to a method. A delegate is created for a particular method signature (for example, "this method accepts two integers and returns a float"). It can then be directed at a method in a class that matches that signature. Note that the delegate instance holds two items, a reference to the instance of the class that contains the method and a reference to the method itself. The fact that a delegate is an object means that a program can pass it around like any other object.

You can use delegates to inform event generators, such as input pins and timers, of the methods they are to call when the event they generate takes place.

Electrically Erasable Programmable Read-Only Memory (EEPROM)

The behavior of an EEPROM is like a read-only memory (ROM) because data written into the device persists when you turn the system off. However, unlike a ROM, from which erasing data is impossible, a program can erase a bank of EEPROM memory. It is not possible to use EEPROM as normal random access memory (RAM) because the erase cycle is very slow and consumes much power. It is also only possible to erase EEPROM storage a limited number of times before the memory components wear out. EEPROM is popular for storing program code and for nonvolatile mass storage devices such as memory cards. You can use it in devices supporting the .NET Micro Framework as a means by which programs can store settings and log data. The mechanism by which programs access it is based on extended weak references, described in Chapter 5, "Developing for the .NET Micro Framework."


An enumeration type is useful in C# when a variable can occupy one of a number of possible states. It is possible to do without enumerations, but using them does make code clearer and less prone to error. They frequently appear within the libraries to represent a set of possible values.

Fully Qualified Name

A fully qualified name is a name that will uniquely identify a class or interface within a particular namespace. The fully qualified name can refer to a resource, even if the namespace is in use.


You create a hierarchy when you extend a parent class to produce a new child class with all the abilities of the parent plus new and modified behaviors specific to the requirements of the child. Extending the child produces a further level of hierarchy. The classes at the top of the hierarchy should be more general and possibly abstract (for example, Sensor), and the classes at the lower levels should be more specific (for example, HighResolutionIRSensor).


An immutable object cannot be changed. If an attempt is made to change the content of an immutable object, a new object is created with the changed content and the old one remains unchanged in memory. The string class is immutable. This gives strings a behavior similar to value types, which makes them easier to use in programs.


Inheritance is the way in which a class extends a parent to allow it to make use of all the behaviors and properties of the parent but add or customize these for a slightly different requirement. For more detail, see the description of hierarchy.


An interface defines a set of actions. The actions are defined in terms of a number of method definitions. A class that implements an interface must contain code for each of the methods. Programs can reference a class that implements an interface purely in terms of that interface. Interfaces make it possible to create components. You don't care precisely what the component is; as long as it implements the interface, you can think of it purely in terms of that ability. A given class can implement multiple interfaces. A reference to an interface can refer to an instance of any class that implements that interface, and you can cast references to interface references. There is a convention in C# that the letter I precedes the identifier given to an interface to distinguish it from classes.


A library is a set of classes used by other programs. The difference between a library and a program is that the library file will have the extension .dll (dynamic-link library) and will not contain a main method.


A namespace is a logical space within which a particular set of names has meaning. Within your programs you will refer to things by identifiers that you devise. At one point during a development, you may create a class called SensorReading, which holds a reading from a particular sensor. However, other programmers on the same project may also create a class with this name. If your code and theirs are combined, that will confuse the compiler because there will be multiple classes with the same name. You can solve the problem by using namespaces.

The namespace keyword lets you create namespaces.

 namespace FrontSensors {    class SensorReading    {    } } namespace BackSensors {    class SensorReading    {    } } 

The preceding code creates two namespaces called FrontSensors and Back-Sensors. Each of the namespaces contains a class called SensorReading. You can create an instance of the SensorReading class for the back sensors by using its fully qualified name.

 BackSensors.SensorReading s = new BackSensors.SensorReading(); 

The fully qualified name for a class includes the namespace within which it is defined. A namespace can extend over a number of source files and has no implications for the physical location of the program source code.

You can use the fully qualified name of a class to uniquely identify any class or interface in a project. However, it is somewhat tedious to have to use all this text each time you want to make use of a class. For this reason, C# provides the using directive.

 using FrontSensors; 

The using directive must appear at the start of a source file. It identifies a namespace to be used to resolve the names of classes in that file. If you add the preceding line to your program, you can create instances of SensorReading without having to add FontSensors to the name.

You can still use BackSensors.SensorReading, but you will need to give its fully qualified name. You can add multiple using directives at the start of a source file; when you create a new project, you will often find that a number of them have been added automatically. If there is a name clash, for example, you use two namespaces that both contain a class called SensorReading, the compiler will require you to use the fully qualified name for that particular class. It can also be sensible to use the fully qualified name in circumstances where you want a reader of the program source to easily identify where the code defines a class.

Namespaces can be hierarchical, in that one namespace may contain another.

 namespace FrontSensors {    namespace Analog    {       class SensorReading       {       }    } } 

This code creates an Analog namespace within the FrontSensors namespace. The fully qualified name of the SensorReading class is now FrontSensors.Analog.SensorReading. The using directive can specify the contents of a nested namespace.

 using FrontSensors.Analog; 

This means that on a large project you can design a namespace hierarchy that reflects the structure of the development. You will find that the resources provided by the .NET Micro Framework are deployed in a number of namespaces.


The namespace mechanism only applies to the way by which programs identify resources; it does not actually provide the code itself. If you wish to make use of libraries of code that contain namespaces, you must ensure that you correctly set up references to these resources.


An object, created by using the new keyword, is an instance of a class. Programs access objects by means of references to them. The object class is the parent of every single other class. If you create a new class, it will actually be a child class of the object class. This means that every class can do what an object can do, and you can regard every class as an object because you can always manipulate an instance in terms of a reference to its parent.


Overload creates a method with the same name as another, but a different combination of parameters (signature). This allows you to provide multiple ways of performing a particular action.

For example, there are several ways you can set a date value. You can provide yy, mm, and dd values. You could provide a single number, the number of days since January 1, 1980, or you could provide a text string. You could overload a SetDate method by providing three methods with that name that accept three integers, a single integer, and a string, respectively. Programmers frequently overload constructor methods to provide multiple means by which a program can provide data to set up an instance of an object.


An override is a situation in which a method in a child class (a class that extends a parent) has the same signature as the parent method and is called on child instances in preference to the parent one. You use this technique when you want the child to have a different behavior than the parent because it holds different or additional properties. An example of overriding is the case of the ToString method.

The object class (which is the parent class of all others) has a ToString method that just returns the name of the class. Because it would be more useful if the ToString method returned text that describes the content of the instance instead, it is common for a programmer to override the ToString method provided by object and create a method more applicable to a particular class. For example, consider this given a class to hold the name and age of an employee:

 class Employee {    string name;    int age;    public override ToString()    {       return "Name : " + name + " Age : " + age;    } } 

The ToString method in the previous code replaces the behavior of the one in the parent object, so when converting an employee name into a text form, it will produce an appropriate output. Note that to override a method in a child class, you must have declared it with the volatile qualifier. This causes the compiler to generate an extra level of indirection when code calls the method so that the overriding behavior can be inserted.

Embedded Programming with the Microsoft .Net Micro Framework
Embedded Programming with the Microsoft .NET Micro Framework
ISBN: 0735623651
EAN: 2147483647
Year: 2007
Pages: 118

Similar book on Amazon
Getting Started with the Internet of Things: Connecting Sensors and Microcontrollers to the Cloud (Make: Projects)
Getting Started with the Internet of Things: Connecting Sensors and Microcontrollers to the Cloud (Make: Projects)
Expert .NET Micro Framework (Expert's Voice in .NET)
Expert .NET Micro Framework (Expert's Voice in .NET)
Netduino Plus
Netduino Plus
Getting Started with Netduino
Getting Started with Netduino © 2008-2017.
If you may any questions please contact us: