diff --git a/hw1/hw1/Counting.cs b/hw1/hw1/Counting.cs index b8e76f4..66fcee1 100644 --- a/hw1/hw1/Counting.cs +++ b/hw1/hw1/Counting.cs @@ -52,5 +52,40 @@ public class Counting : ICountableVariable // // 注意:是Variable被修改!!! // 如果Variable要被赋予的值与当前的值相同,这并不是被修改! + private int readtimes = 0; + private int writetimes = 0; + private int variable = 0; + public int ReadTimes + { + get + { + return readtimes; + } + } + public int WriteTimes + { + get + { + return writetimes; + } + } + public int Variable + { + get + { + readtimes++; + return variable; + } + set + { + if(value < 0 && variable == 0) {; } + else if (value != variable) + { + writetimes++; + } + variable = value < 0 ? 0 : value; + + } + } } }