结构体20140827

Posted on 2014-08-27 15:12  jack-jms  阅读(119)  评论(0编辑  收藏  举报
  1. 结构体 定义自己的类型my tape
  2. 在main括号外面加public stuct **  **为自己的类型  下边加大括号  括号里是自己的类型里面包括的对象
  3. 在里边写 public +类型+变量名   类型里面可以加自己创建的类型 
  4. 把 中间的class 去掉,新添加的其他新建项也可以用 这个类型
public struct snakepoint
        {
            public int x;
            public int y;
        }
        static void Main(string[] args)
        {
            snakepoint s = new snakepoint();
            s.x = 5;
            s.y = 10;

            ArrayList a = new ArrayList();
            a.Add(s);


            Console.WriteLine((snakepoint )a[0].x+","+((snakepoint)a[0]).y);
        {
            student lch = new student();
            lch.no = 1;
            lch.name = "xxx";
            lch.Cshap = 90;
            lch.web = 78;
            lch.datebase = 83;
            lch.sum = lch.Cshap + lch.web + lch.datebase;
            Console.WriteLine(("学号·{0}姓名·{1}Cshap·{2}web·{3}datebase·{4}总分·{5}"), lch.no, lch.name, lch.Cshap, lch.web, lch.datebase, lch.sum);
        }
        
                
        struct student
        {
            public int no;
            public string name;
            public int Cshap;
            public int web;
            public int datebase;
            public int sum;
        }

 

  

Copyright © 2024 jack-jms
Powered by .NET 8.0 on Kubernetes