From aba1ba101fb42ffca4b0c761142ed462a380b08a Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Thu, 21 Jul 2022 19:46:14 +0800 Subject: [PATCH] hw --- hw1/hw1/Counting.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw1/hw1/Counting.cs b/hw1/hw1/Counting.cs index b8e76f4..b9fcc80 100644 --- a/hw1/hw1/Counting.cs +++ b/hw1/hw1/Counting.cs @@ -52,5 +52,25 @@ public class Counting : ICountableVariable // // 注意:是Variable被修改!!! // 如果Variable要被赋予的值与当前的值相同,这并不是被修改! + private int variable; + public int Variable + { + get + { + readTimes++; + return variable; + } + set + { + int num = value > 0 ? value : 0; + if (num == variable ) return; + writeTimes++; + variable = num; + } + } + private int readTimes; + public int ReadTimes { get => readTimes; } + private int writeTimes; + public int WriteTimes { get => writeTimes; } } }