标签:
为了定义一个结构,您必须使用 struct 语句。struct 语句为程序定义了一个带有多个成员的新的数据类型。
在 C# 中,结构是值类型数据结构。它使得一个单一变量可以存储各种数据类型的相关数据。struct 关键字用于创建结构。
struct student { public string name; public int xuehao; public double fenshu; };
类和结构有以下几个基本的不同点:
using System; struct student { private string name; private int xuehao; private double chengji; } public void getValues(string n, int x, double c) { name = t; xuehao=x; chengji=c; } public void display() { Console.WriteLine("name : {0}", name); Console.WriteLine("xuehao : {0}", xuehao); Console.WriteLine("chengji : {0}", chengji); } }; public class student { public static void Main(string[] args) { student s= new student(); /* 声明s,类型为 student */ student s2 = new student(); /* 声明s2,类型为 student */ /* s1 详述 */ s1.getValues("xuehao", "name", "chengji",+xuehao,name,chengji); /* s 2 详述 */ s2.getValues("xuehao", "chengji", "name", +xuehao,name,chengji); /* 打印s1 信息 */ s1.display(); /* 打印 s2 信息 */ s2.display(); Console.ReadKey(); } }
标签:
原文地址:http://www.cnblogs.com/yuyingming/p/5081692.html