Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
3
4
5
6
7
8
9
10
11
public class Account
{
private decimal balance ;
private string name ;
public string GetName ()
{
return name;
}
public bool SetName (string newName){
{
// Final version will validate the name
name = newName;
return true;
}
// Other get and set methods here
}
12
public class Account
{
private decimal balance ;
private string name ;
public string GetName ()
{
return name;
} This is the data our bank account will hold:
The name of the holder and the balance
public bool SetName (string newName){
{
// Final version will validate the name
name = newName;
return true;
}
// Other get and set methods here
}
13
public class Account
{
These are
private the behaviours
decimal balance ; the account provides
private string name ;
public string GetName ()
{
return name;
}
public bool SetName (string newName){
{
// Final version will validate the name
name = newName;
return true;
}
// Other get and set methods here
}
14
Account rob = new Account();
rob.SetName("Rob");
15
16
17
18
19
20
21
22
FrameworkElement
TextBlock Control
TextBox ContentControl
ButtonBase
Button
23
24
25
26
27
28
29
30
31
32
33
34
private
public
Account
Account
public class Account
{
private int age;
/// rest of account here
}
private
Account
public class Account
{
private int age;
public int GetAge()
{
return this.age;
}
public void SetAge( int inAge )
{
if ( (inAge > 0) && (inAge < 120) )
{
this.age = inAge;
}
}
}
CurrentAccount a = new Account();
a.SetAge(21);
public class Account
{
private int ageValue;
public int Age
{
set
{
if ( (value > 8) && (value < 100) )
ageValue = value;
}
get
{
return ageValue;
}
}
}
value
Account s = new Account ();
s.Age = 21;
Console.WriteLine ( "Age is : " + s.Age );
Account s = new Account ();
int newAge = 150;
s.Age = newAge;
if (s.Age != newAge )
Console.WriteLine ( "Age was not set" );
public int AgeInMonths
{
get
{
return this.ageValue*12;
}
}
49
50
51
52