By Adam Freeman, Allen Jones
Book Price: $44.95 USD
£31.95 GBP
PDF Price: $35.99
Cover | Table of Contents | Colophon
# C#
public class SumNumbers {
private int o_total;
/// <summary>
/// Default constructor - initializes the total to zero
/// </summary>
public SumNumbers( ) {
// initialize the total
o_total = 0;
}
/// <summary>
/// Add a number to the total
/// </summary>
/// <param name="p_number">The number to add</param>
public void AddNumber(int p_number) {
o_total += p_number;
}
/// <summary>
/// Get the total
/// </summary>
/// <returns>The total of all values presented to AddNumber</returns>
public int GetTotal( ) {
return o_total;
}
}
# Visual Basic .NET
Public Class SumNumbers
Private o_total As Integer
Public Sub New( )
' initialize the total
o_total = 0
End Sub
Public Sub AddNumber(ByVal p_number As Integer)
o_total += p_number
End Sub
Public Function GetTotal( ) As Integer
Return o_total
End Function
End Class
SumNumbers class maintains a running total of
integer values using the AddNumber method; the
total value is obtained using the GetTotal method.
The second type, SumArray, defines the static
member SumArrayOfIntegers, which accepts an array
of integers to be added together; this class is a consumer of
SumNumbers.# C#
public class SumArray {
/// <summary>
/// Static method that sums together the values in
/// an array of integers
/// </summary>
/// <param name="p_arr"></param>
/// <returns></returns>
public static int SumArrayOfIntegers(int[] p_arr) {
// create a new instance of SumNumbers
SumNumbers x_sum = new SumNumbers( );
// add each value in the array to the sum
foreach (int x_int in p_arr) {
x_sum.AddNumber(x_int);
}
// return the total from the sum
return x_sum.GetTotal( );
}
}
# Visual Basic .NET
Public Class SumArray
Public Shared Function SumArrayOfIntegers(ByVal p_arr( ) As Integer) _
As Integer
' create a new instance of the SumNumbers class
Dim x_sum As SumNumbers = New SumNumbers
' add each value in the array to the sum
Dim x_int As Integer
For Each x_int In p_arr
x_sum.AddNumber(x_int)
Next
' return the total from the sum
Return x_sum.GetTotal( )
End Function
End Class
makecert -sv MyPrivateKey.pvk TestCert.cer
sv option stores the private key component of
the certificate in a file named
MyPrivateKey.pvk; you will need to use this key
later. You will be prompted to enter a password to protect the
private key file, as shown in Figure 2-6.