Main Site Documentation

Beginners Guide ebook question


#1

In reading the ebook, on page 17 section "7.5 What Assemblies to Add?"
it says for now to add the following assemblies.

GHIElectronics.NETMF.Hardware
GHIElectronics.NETMF.IO
GHIElectronics.NETMF.System
Microsoft.SPOT.Hardware
Microsoft.SPOT.Native
Microsoft.SPOT.Hardware.SerialPort
Microsoft.SPOT.IO
mscorlib
System
System.IO

If i add them they why do i also have to add things like “using” in my application ?
I.E. using GHIElectronics.NETMF.FEZ;

It is not clear to me why i am telling it to add these assemblies but also have to say “using…”

would someone please elaborate.


#2

You don’t HAVE to use Using, but, it makes your code a lot easier if you do. The Using directive allows you to reference objects of a specific type in your code file without having to write out the entire namespace for each object. For Example, if I want to reference the Fez_Pin type in code, I could write out:

GHIElectronics.NETMF.FEZ.Fez_Pin etc every time, OR, I could add

using GHIElectronics.NETMF.FEZ; to the top of my page, and then simply type Fez_Pin anywhere in that code when I want to reference that assembly. Does that make sense?


#3

That is what i first thought, but when i commented out the

“using Microsoft.SPOT.Hardware.SerialPort”

then the compiler complained about this line of code,
SerialPort UART = new SerialPort(“COM1”, 115200);

Even though i had it in my references.


#4

You are required to add using for the file that needs the assemblies you have in your project.

You may have 100 files but only one is “using” the assembly


#5

ok, thanks for the clarification.


#6

The using isn’t required but it does make life easier. For your code to work w/o a using statement, you would have to write it as:

Microsoft.SPOT.Hardware.SerialPort UART = new Microsoft.SPOT.Hardware.SerialPort(“COM1”, 115200);

or an even better syntax would be…

var UART = new Microsoft.SPOT.Hardware.SerialPort(“COM1”, 115200);


#7

Thanks, I have just so much to learn it is becoming overwhelming.


#8
var UART = new Microsoft.SPOT.Hardware.SerialPort("COM1", 115200);

The ONLY time I use var is when using LINQ :wink:


#9

Some people just love to type. Your finger muscles thank you :wink: