From 8acd1b3f2b2ee9f24bc31c35f3018339561d965e Mon Sep 17 00:00:00 2001 From: xiangmy21 Date: Fri, 8 Jul 2022 15:27:33 +0800 Subject: [PATCH] modified Counting.cs --- hw1/hw1/Counting.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw1/hw1/Counting.cs b/hw1/hw1/Counting.cs index b8e76f4..406f85c 100644 --- a/hw1/hw1/Counting.cs +++ b/hw1/hw1/Counting.cs @@ -52,5 +52,20 @@ public class Counting : ICountableVariable // // 注意:是Variable被修改!!! // 如果Variable要被赋予的值与当前的值相同,这并不是被修改! + private int variable; + private int readTimes; + private int writeTimes; + public int Variable + { + get { readTimes++; return variable; } + set + { + int tmp = value>=0 ? value : 0; + if (tmp != variable) writeTimes++; + variable = tmp; + } + } + public int ReadTimes { get => readTimes; } + public int WriteTimes { get => writeTimes; } } }