03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

class Class1<br />

{<br />

static void Main(string[] args)<br />

{<br />

Complex r = new Complex();<br />

string str;<br />

double mag,angle;<br />

System.Console.Write("Enter real value >> ");<br />

str=System.Console.ReadLine();<br />

r.real = Convert.ToInt32(str);<br />

System.Console.Write("Enter imag value >> ");<br />

str=System.Console.ReadLine();<br />

r.imag = Convert.ToInt32(str);<br />

Main(). This is the<br />

entry point in<strong>to</strong> the<br />

program, and defines<br />

the start and<br />

end of the program.<br />

It must be declared<br />

inside a class, and<br />

must be static.<br />

mag=r.mag();<br />

angle=r.angle();<br />

System.Console.WriteLine("Mag is {0} and angle is {1}",mag,angle);<br />

}<br />

}<br />

}<br />

System.Console.ReadLine();<br />

1.6.1 Namespace<br />

For the namespace, the full name of the Complex() class, its full name would be:<br />

ConsoleApplication2.Complex()<br />

Thus we could have used:<br />

ConsoleApplication2.Complex r = new ConsoleApplication2.Complex()<br />

duction <strong>to</strong> .NET<br />

<strong>Intro</strong><br />

but as we are in the same namespace it is possible <strong>to</strong> use the relative form.<br />

1.6.2 using<br />

The using keyword is used imports types from other namespaces. Figure 1.18 shows<br />

types that are imported for System.Console.Writeln(). It is important <strong>to</strong> import the<br />

required namespace for the classes that are required. Examples include:<br />

System:<br />

System.Collections:<br />

System.IO:<br />

Array, Boolean, Byte, Char, Convert, DateTime, Double,<br />

Enum, Int16, Int32, Int64, Math, Random, String, Void<br />

ArrayList, BitArray, Hashtable, Queue, Stack.<br />

BinaryReader, BinaryWriter, File, Stream, StreamWriter,<br />

StreamReader<br />

Agilent .NET Course: <strong>Intro</strong>duction 20

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

Saved successfully!

Ooh no, something went wrong!