为了避免我可以用Google搜索的所有标准答案,我将提供一个你可以随意攻击的例子.
C#和Java(和太多的人)有很多类型的一些"溢出"的行为,我不都不像(如type.MaxValue + type.SmallestValue == type.MinValue例如: int.MaxValue + 1 == int.MinValue).
但是,看到我的恶性,我会通过扩展这种行为来增加对这种伤害的一些侮辱,让我们说一个Overridden DateTime类型.(我知道DateTime密封在.NET中,但是为了这个例子,我使用的是一种与C#完全相同的伪语言,除了DateTime没有密封的事实).
被覆盖的Add方法:
/// <summary>
/// Increments this date with a timespan, but loops when
/// the maximum value for datetime is exceeded.
/// </summary>
/// <param name="ts">The timespan to (try to) add</param>
/// <returns>The Date, incremented with the given timespan.
/// If DateTime.MaxValue is exceeded, the sum wil 'overflow' and
/// continue from DateTime.MinValue.
/// </returns>
public DateTime override Add(TimeSpan …Run Code Online (Sandbox Code Playgroud)