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.

2.6 The Convert class<br />

The convert class includes many methods that may be used <strong>to</strong> convert from one<br />

data type <strong>to</strong> another:<br />

There are other mechanisms from translating. Some classes have a Parse method.<br />

2.6.1 Exercises:<br />

Set the following variables:<br />

Variables <strong>to</strong> be used in the exercise<br />

int i = 99;<br />

DateTime w = Convert.ToDateTime("21 Jun 2004 12:30");<br />

double d = 42.3;<br />

Use these values as input <strong>to</strong> one String.Format or ToString <strong>to</strong> produce each of the<br />

following:<br />

1 Use i <strong>to</strong> produce ʺ0099ʺ<br />

i.ToString(ʺ0000ʺ)<br />

2 Use w <strong>to</strong> produce ʺ21/06/2004 12:30:00ʺ – The default local date format.<br />

3 Use w <strong>to</strong> produce ʺMondayʺ ‐ The day of the week.<br />

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

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

4 Use d <strong>to</strong> produce ʺ42.300ʺ ‐ To exactly 3 decimal places.<br />

5 Use i <strong>to</strong> produce 63 – The hex value of 99<br />

Agilent .NET Course: C# Basics 6

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

Saved successfully!

Ooh no, something went wrong!