:
"" ( "-" ), , , .
, (, ), , ".Count", ( . Google).
:
class pseudoThreadsafeHuman{
private object m_syncobject;
public string firstName;
public string lastName;
public string fullName
get{
lock(m_syncobject)
{
return lastName & "," & firstName;
}
}
set{
lock(m_syncobject)
{
lastName = value.Split(",")[1];
firstName = value.Split(",")[2];
}
}
}
- - :
public void isJohn(pseudoThreadSafeHuman currentPerson) {
if currentPerson.firstName == "John"
{
MessageBox.Show(currentPerson.fullName)
}
}
firstName, lastName fullName - . - , "", if MessageBox.Show().
:
, getInitials (pseudoThreadSafeHuman currentPerson), :
public getInitials(pseudoThreadSafeHuman currentPerson)
string initials = ""
if currentPerson.firstName != "" {
initials += currentPerson.firstName[0]; // crash here if firstName got changed to ""
}
if currentPerson.lastName != "" {
initials += currentPerson.lastName[0]; // crash here if lastName got changed to ""
}
}
. , # ( VB.Net), . , , . , -, - , synclock ( ).