#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
__value struct contact
{
public:
String *email;
long telephone;
contact(String *email,long telephone)
{
this->email=email;
this->telephone=telephone;
}
};
__value struct student
{
public:
long id;
String *name;
String *dept;
contact con;
student(long id,String *name,String *dept,contact con)
{
this->id=id;
this->name=name;
this->dept=dept;
this->con=con;
}
void ShowId( )
{
Console::Write("id=");
Console::WriteLine(this->id);
}
void ShowEmail( )
{
Console::Write("email=");
Console::WriteLine(this->con.email);
}
};
int _tmain()
{
student a,b;
a.id=130103106;
a.name="zhangzujin";
a.dept="math";
a.con.email="zhangzujin360732@163.com";
a.con.telephone=8663057;
a.ShowId( );
contact acon("yangxj4746@163.com",8663045);
b=student(1301030105,"yangxiji","biology",acon);
b.ShowEmail( );
return 0;
}
结构体和类:
1)结构体是值类型,而泪湿引用类型。
2)结构体的各成员的访问控制方式都缺省为公有的,而类的各成员访问方式则缺省为私有的。
3)结构体能更有效的利用内存。