Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp_卜佳木_智10 #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions hw1/hw1/Counting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ public interface ICountableVariable

public class Counting : ICountableVariable
{
private int variable = -1;
private int readTimes;
private int writeTimes;
public int Variable
{
set
{
value = value >= 0 ? value : 0;
writeTimes += (value != variable) ? 1 : 0;
variable = value;
}
get
{
readTimes++;
return variable;
}
}
public int ReadTimes
{
get => readTimes;
}
public int WriteTimes
{
get => writeTimes;
}
// 需要实现:分别统计变量Variable被读取、被修改的次数,只允许修改Counting类中的代码
// 要求:
// 1. Variable 不能被外部程序赋值为负数。若被赋为负数,则将它代表的值置为0。
Expand Down