Skip to content

Instantly share code, notes, and snippets.

@s2kw
Created April 9, 2015 03:47
Show Gist options
  • Save s2kw/2018ffcb0d461ab8f5b7 to your computer and use it in GitHub Desktop.
Save s2kw/2018ffcb0d461ab8f5b7 to your computer and use it in GitHub Desktop.
継承したら継承元から見てもクラス変わってるんだぜ
using System;
using System.Linq;
using System.Collections.Generic;
namespace PlayGrournd
{
class MainClass
{
public static void Main(){
var x = new X ();
x.SayName ();
var xx = new XX ();
xx.SayName ();
var r = new Reader ();
r.ReadName ( x );
r.ReadName (xx);
}
public class X{
public void SayName(){
Console.WriteLine ( "X say:" + this.GetType().Name );
}
}
public class XX:X{
}
public class Reader{
public void ReadName( X _x ){
_x.SayName();
Console.WriteLine( "read:" + _x.GetType().Name );
}
}
}
}
@s2kw
Copy link
Author

s2kw commented Apr 9, 2015

X say:X
X say:XX
X say:X
read:X
X say:XX
read:XX

Press any key to continue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment