Created
March 21, 2021 10:33
-
-
Save kolosovpetro/7f513bd4159cb72138093bd83d2ce0f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Account | |
{ | |
public delegate void AccountHandler(string message); | |
public event AccountHandler Notify; // 1.Определение события | |
public Account(int sum) | |
{ | |
Sum = sum; | |
} | |
public int Sum { get; private set;} | |
public void Put(int sum) | |
{ | |
Sum += sum; | |
Notify?.Invoke($"На счет поступило: {sum}"); // 2.Вызов события | |
} | |
public void Take(int sum) | |
{ | |
if (Sum >= sum) | |
{ | |
Sum -= sum; | |
Notify?.Invoke($"Со счета снято: {sum}"); // 2.Вызов события | |
} | |
else | |
{ | |
Notify?.Invoke($"Недостаточно денег на счете. Текущий баланс: {Sum}"); ; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
using System.Security; | |
using System.Security.Permissions; | |
using System.Threading; | |
[assembly: CompilationRelaxations(8)] | |
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] | |
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] | |
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] | |
[assembly: AssemblyVersion("0.0.0.0")] | |
[module: UnverifiableCode] | |
internal class Account | |
{ | |
public delegate void AccountHandler(string message); | |
[CompilerGenerated] | |
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | |
private AccountHandler m_Notify; | |
[CompilerGenerated] | |
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | |
private int <Sum>k__BackingField; | |
public int Sum | |
{ | |
[CompilerGenerated] | |
get | |
{ | |
return <Sum>k__BackingField; | |
} | |
[CompilerGenerated] | |
private set | |
{ | |
<Sum>k__BackingField = value; | |
} | |
} | |
public event AccountHandler Notify | |
{ | |
[CompilerGenerated] | |
add | |
{ | |
AccountHandler accountHandler = this.Notify; | |
while (true) | |
{ | |
AccountHandler accountHandler2 = accountHandler; | |
AccountHandler value2 = (AccountHandler)Delegate.Combine(accountHandler2, value); | |
accountHandler = Interlocked.CompareExchange(ref this.Notify, value2, accountHandler2); | |
if ((object)accountHandler == accountHandler2) | |
{ | |
break; | |
} | |
} | |
} | |
[CompilerGenerated] | |
remove | |
{ | |
AccountHandler accountHandler = this.Notify; | |
while (true) | |
{ | |
AccountHandler accountHandler2 = accountHandler; | |
AccountHandler value2 = (AccountHandler)Delegate.Remove(accountHandler2, value); | |
accountHandler = Interlocked.CompareExchange(ref this.Notify, value2, accountHandler2); | |
if ((object)accountHandler == accountHandler2) | |
{ | |
break; | |
} | |
} | |
} | |
} | |
public Account(int sum) | |
{ | |
Sum = sum; | |
} | |
public void Put(int sum) | |
{ | |
Sum += sum; | |
AccountHandler notify = this.Notify; | |
if (notify != null) | |
{ | |
notify(string.Format("На счет поступило: {0}", sum)); | |
} | |
} | |
public void Take(int sum) | |
{ | |
if (Sum >= sum) | |
{ | |
Sum -= sum; | |
AccountHandler notify = this.Notify; | |
if (notify != null) | |
{ | |
notify(string.Format("Со счета снято: {0}", sum)); | |
} | |
} | |
else | |
{ | |
AccountHandler notify2 = this.Notify; | |
if (notify2 != null) | |
{ | |
notify2(string.Format("Недостаточно денег на счете. Текущий баланс: {0}", Sum)); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"target": "C#", | |
"mode": "Debug" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment