首页 > 代码库 > 结构体

结构体

  //结构体 定义自己的类型my tape

            //在main括号外面加public stuct **  **为自己的类型  下边加大括号  括号里是自己的类型里面包括的对象

            //在里边写 public +类型+变量名   类型里面可以加自己创建的类型  

            //把 中间的class 去掉,新添加的其他新建项也可以用 这个类型

            //例

 

             /*

             public struct snakepoint

             {

                 public int x;

                 public  int y;

             }

           public  struct student

                  {

                      public int 学号;

                      public string 名字;

                      public int csharp;

                      public int 网页;

                      public int 数据库;

                      public int 总分;

                      public int 名次;

                      public snakepoint 坐标;

                   }

 

          

                 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);

            */

          

 

 

 

 

            //输入学生信息并成绩排名

            /*

            //输入部分  加求总成绩

            Console.WriteLine("请输入信息:");

             student []a=new student [5];

            for (int i = 0; i < 5;i++ )

            {

                a[i].学号 =i+1;

                Console.Write("输入名字:");

                a[i].名字 = Console.ReadLine();

                Console.Write("输入c#成绩:");

                a[i].csharp = Convert.ToInt32(Console.ReadLine());

                Console.Write("输入网页成绩:");

                a[i].网页 = Convert.ToInt32(Console.ReadLine());

                Console.Write("输入数据库成绩:");

                a[i].数据库 = Convert.ToInt32(Console.ReadLine());

              

                a[i].总分 = a[i].csharp + a[i].数据库 + a[i].网页;

              

            } 

            

            

            //根据总分排名

            for (int i = 0; i < 5; i++)

            {

                for (int m = 0; m < i; m++)

                {

                    if (a[m].总分 < a[i].总分)

                    {

                        student n = a[m];

                        a[m] = a[i];

                        a[i] = n;

                    }

                   

                }

             

            }

             //输出部分

            Console.WriteLine("学号\t姓名\tc#\t网页\t数据库\t总分\t名次");

            for (int i = 0; i < 5;i++ )

            {

                a[i].名次 = i + 1;

                Console.WriteLine(a[i].学号 +"\t"+a[i].名字 +"\t"+a[i].csharp+"\t"+a[i].网页+"\t"+a[i].数据库+"\t"+a[i].总分+"\t"+a[i].名次);

            }

 

            */

 

结构体