Complete set: Intro to C - Bill Buchanan
Complete set: Intro to C - Bill Buchanan
Complete set: Intro to C - Bill Buchanan
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
4 Types and Debugging<br />
4.1 <strong>Intro</strong>duction<br />
This module covers the key elements of arrays, indexers and collections. It covers:<br />
• Reference types.<br />
• Common reference type.<br />
• Namespaces and object hierarchy.<br />
• Debugging.<br />
4.2 Reference Types<br />
Parameters are passed in<strong>to</strong> function member, such as methods or properties,<br />
either using a value or a reference. If a value is passed, only the contents of<br />
the value are used, thus it cannot be modified. It a reference it passed, the<br />
function member can modify the value. A value passed by reference uses the<br />
ref keyword, such as:<br />
swap(ref int a, ref int b)<br />
duction <strong>to</strong> .NET<br />
<strong>Intro</strong><br />
4.2.1 Passing Value-Type Parameters<br />
This is the simplest case, where a copy of the value of the data is passed. Thus an<br />
changes <strong>to</strong> the parameters will be lost. For example in Figure 4.1 the value of val1 is<br />
passed in x. This is then modified in the method <strong>to</strong> give the square of the value.<br />
When it returns from the method, it can be seen from the sample run that the value<br />
of val1 has not change (as it remains at 10).<br />
Program 4.1: Program4_1_PassingByValue<br />
using System;<br />
namespace ConsoleApplication2<br />
{<br />
class Class1<br />
{<br />
static double findSquare(double x)<br />
{<br />
Agilent .NET Course: Type and Debugging 2