试题详情
简答题编一个程序,定义结构(有姓名,年龄,手机号码三个字段),再定义一个一维数组,把结构作为数组元素类型,存入数据,然后依次输出。
  • structContact
    {
    publicstringname;
    publicintage;
    publicstringtelephone;
    }
    classProgram
    {
    staticvoidMain(string[]args)
    {
    Contact[]c=newContact[3];
    //c[0]=newContact();//此三个语句,对于结构类型可以不用
    //c[1]=newContact();
    //c[2]=newContact();
    c[0].name="刘龙";
    c[0].age=54;
    c[0].telephone="13970861234";
    c[1].name="王鸣";
    c[1].age=42;
    c[1].telephone="13813254321";
    c[2].name="张星";
    c[2].age=39;
    c[2].telephone="13751461818";
    Console.Write("姓名:{0},",c[0].name);
    Console.Write("年龄:{0},",c[0].age);
    Console.WriteLine("手机号码:{0}",c[0].telephone);
    Console.Write("姓名:{0},",c[1].name);
    Console.Write("年龄:{0},",c[1].age);
    Console.WriteLine("手机号码:{0}",c[1].telephone);
    Console.Write("姓名:{0},",c[2].name);
    Console.Write("年龄:{0},",c[2].age);
    Console.WriteLine("手机号码:{0}",c[2].telephone);
  • 关注下方微信公众号,在线模考后查看

热门试题