本帖最后由 刘景发 于 2011-11-21 13:00 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
enum Gender
{
男,
女
}
public struct Person //定义一个名叫Person的结构
{
public string name;//结构的成员
public Gender sex; //出错位置。错误 1 可访问性不一致: 字段类型“ConsoleApplication1.Gender”比字段“ConsoleApplication1.Person.sex”的可访问性低.
public int age;
}
class Program
{
static void Main(string[] args)
{
Person onePerson;
onePerson.name = "张三";
onePerson.sex = Gender.男;
onePerson.age = 20;
Console.WriteLine("大家好!我叫:{0},我今年:{1}岁了,我是:{2}性",
onePerson.name, onePerson.age, onePerson.sex);//有英文状态下的逗号可以换行
Person secPerson;
secPerson.name = "李四";
secPerson.sex = Gender.女;
secPerson.age = 18;
Console.WriteLine("大家好!我叫:{0},我今年:{1}岁了,我是:{2}性",
secPerson.name,secPerson.age,secPerson.sex);
Console.ReadKey();
}
}
}
|