首页 > 代码库 > 对象数组

对象数组

using System;using System.Collections.Generic;using System.Linq;using System.Text;using nange;namespace ConsoleApplication1{    class Program    {      public static void menu()        {            Console.WriteLine("第一个c#程序");        }    }     class Program_1{         string name;         Program_1(string str)         { name = str;            Console.WriteLine("构造函数执行成功"+name);          }         void init()         {             int i = 0;             Data[] data = new Data[3];             for (i = 0; i < 3; i++)                 data[i] = new Data();             for (i = 0; i < 3; i++)                 data[i].input();             for (i = 0; i < 3; i++)             {                 Console.WriteLine("姓名" + data[i].name);                 Console.WriteLine("年龄" + data[i].age);             }         }        static void Main(string[] args)         {             Program.menu();              Program_1 test = new Program_1("test");             test.init();             Console.ReadLine();        }    }}namespace nange{    class Data    {        public string name;  //这些必需要加public,否则会出错的        public int age;        public void input()        {Console.WriteLine("输入姓名");         name=Console.ReadLine();         Console.WriteLine("输入年龄");         age=Convert.ToInt32(Console.ReadLine());        }                 }}   

 

对象数组