using System;
public struct Point 
{
public int x, y;
public string myStr; public Point(int x, int y,string tempStr) 
{
this.x = x;
this.y = y; 
this.myStr = tempStr;
}
}class MainClass 
{
public static void Main() 
{
// Declare an object:
string deStr = "abcde";
//Point myPoint = new Point();
Point myPoint = new Point(10,10,deStr);
// Display results:
// Initialize:
//myPoint.x = 10;
//myPoint.y = 20;
//myPoint.myStr = "wxyz";
Console.WriteLine("My Point:");
Console.WriteLine("x = {0}, y = {1}", myPoint.x, myPoint.y);
Console.WriteLine(myPoint.myStr);
}
}

解决方案 »

  1.   

    你可以看看System.Activator.CreateInstance()方法的重载,可以解决你的问题
      

  2.   

    晕!不会我把题看错了吧!呵呵!
    假如这样的话:
    using System;
    public struct Point 
    {
    public  int x, y;
    public void print()
    {
    Console.Write("OK");
    }
    }class MainClass 
    {
    public static void Main() 
    {

    string className = "Point";

    Type classType = Type.GetType(className);
    //这里classType 总为null???

    Point obj = (Point)(Activator.CreateInstance(classType)); obj.print();
    }
    }
      

  3.   

    谢谢 snewxf(心疤),
    但Point类的构造函数的参数,在哪里传
      

  4.   

    string t = "System.String";object[] args = new object[1] { new char[]{'a','b','c'} };object strInstance = Activator.CreateInstance( Type.GetType( t ),args );
    //用Object数组传递参数
      

  5.   

    yes,createInstance的時候,注意最後一個參數的填寫就可以了。