using System;
public class Program
{
public class B {
private int _x;
public virtual void SetX(int x) {
if (x < 0) throw new Exception("less 0");
else _x = x;
}
public class A : B {
public override void SetX(int x) {
if (x > 100) throw new Exception("more 100");
base.SetX(x);
public static void Foo(B b) { b.SetX(100500); }
public static void Main()
var b = new B();
var a = new A();
Foo(b);
Foo(a);