All pastes #770783 Raw Edit

Vic

public text v1 · immutable
·published 2007-11-12 16:14 UTC
rendered paste body
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            float asFloat = 1.0f;
            object asObject = asFloat;

            IList list = CreateList(asObject);

            // list is actually List<float>.  AMAZING!
        }


        static IList CreateList(object unknownTypeObject)
        {
            Type t = typeof(List<>).MakeGenericType(unknownTypeObject.GetType());
            object obj = Activator.CreateInstance(t);
            return obj as IList;

        }
    }
}