C#数组存入引用类型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ControlProject
{
    class User
    {
        public string Name
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }

        public User() 
        {
        
        }

        public User(string name,int age)
        {
            this.Name = name;
            this.Age = age;
        }


    }
    class Program
    {
        static void Main(string[] args)
        {
            User u1 = new User("神秘藏宝室",26);
            User u2 = new User("神秘", 26);
            User u3 = new User("藏宝室", 26);

            User[] myUser = { u1, u2, u3 };

            foreach(User u in myUser)
            {
                Console.WriteLine("用户:{0},年龄:{1}", u.Name, u.Age);
            }

        }
    }
}
posted on 2013-11-06 15:21  神秘藏宝室  阅读(414)  评论(0编辑  收藏  举报

 >>>转载请注明出处<<<