ms-help://MS.VSCC/MS.MSDNVS.2052/csref/html/vcrefStructTypes.htm

解决方案 »

  1.   

    今天刚重装机子,还没装MSDN,麻烦谁帖一下
      

  2.   

    struct 类型是一种可包含构造函数、常数、字段、方法、属性、索引器、运算符和嵌套类型的值类型。struct 类型的声明格式如下:[attributes] [modifiers] struct identifier [:interfaces] body [;]
    此处: attributes(可选) 
    附加的声明性信息。有关属性和属性类的更多信息,请参阅 17. 属性。 
    modifiers(可选) 
    允许使用的修饰符有 new 和四个访问修饰符。 
    identifier 
    struct 名称。 
    interfaces(可选) 
    包含结构所实现的接口的列表,接口间由逗号分隔。 
    body 
    包含成员声明的结构体。 
    备注
    struct 类型适合表示如点、矩形和颜色这样的轻量对象。尽管可能将一个点表示为类,但结构在某些方案中更有效。例如,如果声明一个含有 1000 个点对象的数组,则将为引用每个对象分配附加的内存。在此情况下,结构的成本较低。声明结构的默认(无参数)构造函数是错误的。总是提供默认构造函数以将结构成员初始化为它们的默认值。在结构中初始化实例字段是错误的。使用 new 运算符创建结构对象时,将创建该结构对象,并且调用适当的构造函数。与类不同的是,结构的实例化可以不使用 new 运算符。如果不使用 new,那么在初始化所有字段之前,字段将保持未赋值状态且对象不可用。对于结构,不像类那样存在继承。一个结构不能从另一个结构或类继承,而且不能作为一个类的基。但是,结构从基类 Object 继承。结构可实现接口,其方式同类完全一样。与 C++ 不同,无法使用 struct 关键字声明类。在 C# 中,类与结构在语义上是不同的。结构是值类型,而类是引用类型。有关值类型功能的更多信息,请参阅值类型。除非需要引用类型语义,否则,小于 16 字节的类被系统作为结构处理可能更高效。有关结构的更多信息,请参阅 11. 结构和结构教程。在 C++ 的托管扩展中,与 C# 类和 C# 结构等效的类和结构如下所示:C# C++ 的托管扩展 有关更多信息 
    类 __gc 结构

    __gc 类 __gc 关键字 
    结构 __value 结构

    __value 类 __value 关键字 示例 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
      

  3.   

    我不是要struct说明,还是要Socket里发送struct,客户端解码等资料哇
      

  4.   

    sosososososososososososoosososososososososos