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.

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

}<br />

}<br />

}<br />

Sample Run<br />

Name: fred<br />

If we now change the class <strong>to</strong>:<br />

class Test<br />

{<br />

static void Main()<br />

{<br />

Profile p1 = new Profile();<br />

Profile p2 = new Profile();<br />

p1.Name="Fred";<br />

p2.Name="Bert";<br />

}<br />

}<br />

p1.ToLowerCase();<br />

p1.Display();<br />

p2.Display();<br />

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

Then the output will become:<br />

Name: fred<br />

Name: Bert<br />

Where the first name (Fred) has had the ToLowerCase() method applied <strong>to</strong> it, but<br />

the second one (Bert) has not.<br />

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

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

7.5 Sealed classes<br />

The sealed modifier is used <strong>to</strong> bar classes from deriving its members, and is used <strong>to</strong><br />

prevent deviation from the original purposes of a class. For example, if in Program<br />

7.6 we change the People class <strong>to</strong>:<br />

sealed class People<br />

{<br />

private string name;<br />

public string Name {<br />

get {return name;}<br />

<strong>set</strong> {name=value;}<br />

}<br />

Agilent .NET Course: Objects 12

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

Saved successfully!

Ooh no, something went wrong!