“结构”示例

本示例演示结构的语法和用法。它还介绍了类与结构之间的重大差异。有关更多信息,请参见对象、类和结构(C# 编程指南)

安全说明

提供此代码示例是为了阐释一个概念,它并不代表最安全的编码实践,因此不应在应用程序或网站中使用此代码示例。对于因将此代码示例用于其他用途而出现的偶然或必然的损害,Microsoft 不承担任何责任。

在 Visual Studio 中生成并运行“结构”示例

  1. “解决方案资源管理器”中,右击“Struct1”项目并单击“设为启动项目”。

  2. (-:From the Debug menu, click Start Without Debugging.)=100%(在“调试”菜单中,单击“开始执行(不调试)”。:-)

  3. (-:Repeat the preceding steps for Struct2.)=100%(对于 Struct2,请重复前面的步骤。:-)

(-:To build and run the Structs samples from the Command Line)=100%(从命令行生成并运行“结构”示例:-)

  1. (-:Use the Change Directory command to change to the Struct1 directory.)=100%(使用“更改目录”命令转到“Struct1”目录。:-)

  2. (-:Type the following:)=100%(键入以下命令::-)

    csc struct1.cs
    struct1
  3. 使用“更改目录”命令转到“Struct2”目录。

  4. 键入以下命令:

    csc struct2.cs
    struct2