本文介绍了何时使用Structure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 为什么我们在c#中使用结构以及何时使用结构? 先谢谢你的帖子。Why do we use structure and when to use structure in c#? Thanks in Advance for your posts.推荐答案 [attributes] [modifiers] struct identifier [:interfaces] body [;] 其中: 属性(可选) 附加声明性信息。有关属性和属性类的更多信息,请参见17.属性。 修饰符(可选) 允许的修饰符是新的和四个访问修饰符。 标识符 结构名称。 接口(可选) 包含结构实现的接口的列表,全部由逗号。 正文 包含成员声明的结构体。 示例: where:attributes (Optional)Additional declarative information. For more information on attributes and attribute classes, see 17. Attributes.modifiers (Optional)The allowed modifiers are new and the four access modifiers.identifierThe struct name.interfaces (Optional)A list that contains the interfaces implemented by the struct, all separated by commas.bodyThe struct body that contains member declarations.Example:// keyword_struct.cs// struct declaration and initializationusing 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); }} 输出: Output:My Point: x = 0, y = 0Your Point: x = 10, y = 10 这篇关于何时使用Structure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 07:15