当然需要先new一个实例,然后再给实例的属性赋值啊

解决方案 »

  1.   

    使用 new 运算符创建结构对象时,将创建该结构对象,并且调用适当的构造函数。与类不同的是,结构的实例化可以不使用 new 运算符。如果不使用 new,那么在初始化所有字段之前,字段将保持未赋值状态且对象不可用。
      

  2.   

    有两种使用方式:
    一直接声明,声明后对其变量的属性一一赋值;
    二用new 来声明,用方法或直接对其赋值.
      

  3.   

    在见msdn.有如下的一段示例:
    示例 1
    下面举例说明了同时使用默认构造函数和参数化构造函数的 struct 初始化。
    // keyword_struct.cs
    // struct declaration and initialization
    using System;
    public struct Point 
    {
       public int x, y;   public Point(int p1, int p2) 
       {
          x = p1;
          y = p2;    
       }
    }class MainClass 
    {
       public static void Main()  
       {
          // Initialize:   
          Point myPoint = new Point();
          Point yourPoint = new Point(10,10);      // Display results:
          Console.Write("My Point:   ");
          Console.WriteLine("x = {0}, y = {1}", myPoint.x, myPoint.y);
          Console.Write("Your Point: ");
          Console.WriteLine("x = {0}, y = {1}", yourPoint.x, yourPoint.y);
       }
    }
    输出
    My Point:   x = 0, y = 0
    Your Point: x = 10, y = 10
    示例 2
    下面举例说明了结构特有的一种功能。该功能创建点对象时不使用 new 运算符。如果将 struct 换成 class,程序将不编译。
    // keyword_struct2.cs
    // Declare a struct object without "new"
    using System;
    public struct Point 
    {
       public int x, y;   public Point(int x, int y) 
       {
          this.x = x;
          this.y = y; 
       }
    }class MainClass 
    {
       public static void Main() 
       {
          // Declare an object:
          Point myPoint;      // Initialize:
          myPoint.x = 10;
          myPoint.y = 20;      // Display results:
          Console.WriteLine("My Point:");
          Console.WriteLine("x = {0}, y = {1}", myPoint.x, myPoint.y);
       }
    }
    输出
    My Point:
    x = 10, y = 20