• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
疯丫头0805
博客园    首页    新随笔    联系   管理    订阅  订阅
5月12日 结构体
一、结构体定义:

结构体一般定义在Main函数上面,位于Class下面,作为一个类;一般情况Struct定义在Main函数前面,Main函数里面的地方都可以使用,参数前面加上public代表公用变量。

二、格式:

         struct +结构体的名称

         {

            public int+变量名;

            public string+变量名;

            public int+变量名;

         }


namespace
_5月12日_结构体 { class Program { struct student { public int num; public string name; public string sex; public int[] qq; public One oone; } struct One { public string aa; public int bb; } static void Main(string[] args) { student stu = new student(); stu.oone.aa = "123"; stu.oone.bb = 123; stu.qq = new int[10]; Console.WriteLine(stu.qq[0]);//中括号里没有内容显示non //初始化结构体 //student stu = new student(); //stu.num = 1; //stu.name = "张三"; //stu.sex = "男"; //student stu2 = new student(); //stu2.num = 2; //stu2.name = "李四"; //stu2.sex = "女"; Console.ReadLine(); } } }

 

posted on 2016-05-13 17:54  疯丫头0805  阅读(125)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3