If you're struggling to understand what protected
means, here's a simple example:
class Tile
{
internal static void Test(Tile t)
{
object mc = t.MemberwiseClone(); // works fine!
}
}
class TypeFromWhichTileDoesNotDerive
{
internal static void Test(Tile t)
{
object mc = t.MemberwiseClone(); // illegal, will not compile
}
}
As you see, you can call the protected
method (inherited from System.Object
) on a Tile
object t
only if you are inside the Tile
class (or inside some base class of Tile
).
So if you want to take advantage of the MemberwiseClone
method (be sure to understand what kind of clone it gives, a "shallow" clone), simply make a method inside the Tile
class that calls MemberwiseClone
on a Tile
. Other code outside the Tile
class can then call your method (depending on whether your method is private
, internal
, protected
, public
).