That Keyword


Written on Monday, June 18, 2007 by

Brian Keller posed a question to the readers of his blog asking what we thought, if there were such a thing, the "that" keyword should do in C#. What a fantastic idea! My suggestion - the that keyword would be used to allow access to inherited classes from the base class.

public class MyBase
{
    public MyBase()
    {
 	//only call CallToMethod() in a specific class
 	if( typeof(that).ToString().Equals("MyChild") )
 		that.CallToMethod();
    }
}

public class MyChild : MyBase
{
    public void CallToMethod()
    {
        // more code goes here...
    }
}

Yeah I know it's really dangerous and would definitely have some overhead associated with it but the functionality would be awesome!

Back

Let's talk about this

 


The opinions expressed herein are my own and do not represent my employer's view in any way.


Creative Commons License