Does anyone know why the following code doesn't "do the expected thing" ? I
think I've properly coded my intent in C# but I could be wrong.


I'm trying to get the base class static methods to act differently based on
static data in the derived classes.


- Edward -



using System.Collections.Generic;

public class Vehicle {
        protected const string REG_TYPE = "";
        protected static string TAX_CAT = "";
        
        public static string getRegType() where T : Vehicle
        {
                return T.REG_TYPE;
        }
        
        public static string getTaxCategory() where T : Vehicle
        {
                return T.TAX_CAT;
        }
}

public class Truck : Vehicle {
        protected new const string REG_TYPE = "G";
        protected new static string TAX_CAT = "J4";
}

public class GenericsBug {
        public static void Main(string[] args)
        {
                System.Console.WriteLine("Registration Class: " + 
Truck.getRegType());
                System.Console.WriteLine("Tax Category: " + 
Truck.getTaxCategory());
        }
}


-- 
View this message in context: 
http://www.nabble.com/Parametized-generics-puzzler-tp21704985p21704985.html
Sent from the Mono - General mailing list archive at Nabble.com.
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to