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 />

Profile pf1=new Profile("00000");<br />

pf1.Name="Fred Smith";<br />

pf1.Telephone="123456";<br />

pf1.Display();<br />

}<br />

}<br />

}<br />

Sample Run<br />

Code: 00000 Name: Fred Smith Telephone: 123456<br />

8.4 Destruc<strong>to</strong>rs<br />

A destruc<strong>to</strong>rs is the opposite of a construc<strong>to</strong>r, and occur when an object is deleted. It<br />

is defined in the class with:<br />

~ClassName()<br />

{<br />

// Destruc<strong>to</strong>r coce<br />

}<br />

For example in the previous example we could have added:<br />

~Profile()<br />

{<br />

Console.WriteLine("Getting rid of object .. " + this.ToString());<br />

}<br />

To display when the objects were deleted.<br />

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

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

8.5 Static and Instance Members<br />

A class can either have static members of instance members. Instance members relate<br />

<strong>to</strong> the object created, while static members can be used by referring <strong>to</strong> the name<br />

of the method within the class. For example the following are calls <strong>to</strong> static members:<br />

Convert.ToInteger("str");<br />

Console.WriteLine("Hello");<br />

Whereas in the following, there are two instance methods (Read() and Write()),<br />

Agilent .NET Course: More Objects 10

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

Saved successfully!

Ooh no, something went wrong!