A simple question arises regarding the use of generics or not, and if so, is this the right way?
A typical non-generic version looks like this:
public interface IFood { string name { get; set; } } public class Vegetables : IFood { #region IFood Members public string name { get { return "Cabbage"; } set{ } } #endregion } public class Cow { private IFood _food; public Cow(IFood food) { _food = food; } public string Eat() { return "I am eating " + _food.name; } }
The general version is as follows:
public class Cow<T> where T : IFood { private T _food; public Cow(T food) { _food = food } public string Eat() { return "I am eating " + _food.name; } }
Am I doing everything right in the generic version? Do I need to use a universal version for future growth? This is just a simple layout of the source script, but it is completely reminiscent.
source share