Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Program
- {
- public interface IConvertible<T>
- {
- T Convert();
- T Convert<T>();
- }
- public class ConvertMe : IConvertible<int>, IConvertible<float>
- {
- public double Value;
- int IConvertible<int>.Convert() { return (int)Value; }
- float IConvertible<float>.Convert() { return (float)Value; }
- public T Convert<T>() { return ((IConvertible<T>)this).Convert(); }
- }
- public static void Main()
- {
- ConvertMe c = new ConvertMe();
- c.Value = 12.3456789;
- Console.WriteLine(c.Convert<int>());
- Console.WriteLine(c.Convert<float>());
- Console.ReadKey();
- }
- }
- public interface IConvertible<T>
- {
- T Convert();
- }
- public sealed class ConvertMe : IConvertible<int>, IConvertible<float>
- {
- public double Value;
- int IConvertible<int>.Convert() { return (int)Value; }
- float IConvertible<float>.Convert() { return (float)Value; }
- }
- public static class Program
- {
- public static void Main()
- {
- ConvertMe c = new ConvertMe();
- c.Value = 12.3456789;
- Console.WriteLine(((IConvertible<int>)c).Convert());
- Console.WriteLine(((IConvertible<float>)c).Convert());
- }
- }
- public static class Specialisation
- {
- public static Specialisation<T> For<T>()
- {
- return Specialisation<T>.Instance;
- }
- }
- Specialised s = new Specialised();
- s.Value = 12.3456789;
- Console.WriteLine(s.SpecialisedMethod(Specialisation.For<int>()));
- Console.WriteLine(s.SpecialisedMethod(Specialisation.For<float>()));
- Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement