c#关建字—struct
单词struct:结构
基本格式为:
struct 结构体名
{
结构体属性
结构体方法(选填)
}
比如定义一部手机:
struct Phone
{
public string Brand;//品牌
public string Model;//型号
public string Processor;//处理器
public string Pixel;//像素
}
public void PrintPhonestruct()
{
Console.WriteLine("品牌 = {0} 型号 = {1} 处理器 = {2} 像素 = {3}", Brand, Model, Processor, Pixel);
}
那么结构体该如何使用了,如下:
class Program
{
static void Main(string[] args)
{
Phone phone1;
phone1.Brand = "OPPO";
phone1.Model = "v91";
phone1.Processor = "v970";
phone1.Pixel = "200000";
phone1.PrintPhonestruct();
}
}