G
Guest
I have a simple situation in which I want to use generics along with dynamic
type assignment. Following code snippet can explain in more detail
But I am unable to do that will anybody help me why?
namespace genericTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Type X = System.Type.GetType("System.Int32");
GetMyTypes<X> a = new GetMyTypes<X>();
a.MyTypes = "Going out";
MessageBox.Show(a.MyTypes.ToString());
}
}
public class GetMyTypes<T>
{
T t;
public T MyTypes
{
get { return t; }
set { t = value; }
}
}
}
Errors
Error 1 The type or namespace name 'X' could not be found (are you missing a
using directive or an assembly reference?)
type assignment. Following code snippet can explain in more detail
But I am unable to do that will anybody help me why?
namespace genericTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Type X = System.Type.GetType("System.Int32");
GetMyTypes<X> a = new GetMyTypes<X>();
a.MyTypes = "Going out";
MessageBox.Show(a.MyTypes.ToString());
}
}
public class GetMyTypes<T>
{
T t;
public T MyTypes
{
get { return t; }
set { t = value; }
}
}
}
Errors
Error 1 The type or namespace name 'X' could not be found (are you missing a
using directive or an assembly reference?)